[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> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12 | #include <memory> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame^] | 13 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 14 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 16 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 17 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 23 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 24 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 25 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.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" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame^] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 45 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 46 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 47 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 48 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 52 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 56 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 57 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 58 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 59 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 61 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 62 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 70 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 71 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 72 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 73 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 74 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 75 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 79 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 80 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 82 | #include "net/socket/socket_test_util.h" |
| 83 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 84 | #include "net/spdy/spdy_framer.h" |
| 85 | #include "net/spdy/spdy_session.h" |
| 86 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 87 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 88 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 89 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 90 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_config_service_defaults.h" |
| 92 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 93 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 94 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 95 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 96 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 97 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 98 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 99 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 100 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 101 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 103 | using net::test::IsError; |
| 104 | using net::test::IsOk; |
| 105 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 106 | using base::ASCIIToUTF16; |
| 107 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 108 | //----------------------------------------------------------------------------- |
| 109 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 110 | namespace net { |
| 111 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 112 | namespace { |
| 113 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame^] | 114 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 115 | public: |
| 116 | TestNetworkStreamThrottler() |
| 117 | : throttle_new_requests_(false), |
| 118 | num_set_priority_calls_(0), |
| 119 | last_priority_set_(IDLE) {} |
| 120 | |
| 121 | ~TestNetworkStreamThrottler() override { |
| 122 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 123 | } |
| 124 | |
| 125 | // NetworkThrottleManager |
| 126 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 127 | RequestPriority priority, |
| 128 | bool ignore_limits) override { |
| 129 | std::unique_ptr<TestThrottle> test_throttle( |
| 130 | new TestThrottle(throttle_new_requests_, delegate, this)); |
| 131 | outstanding_throttles_.insert(test_throttle.get()); |
| 132 | return std::move(test_throttle); |
| 133 | } |
| 134 | |
| 135 | void UnthrottleAllRequests() { |
| 136 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
| 137 | for (auto& throttle : outstanding_throttles_copy) { |
| 138 | if (throttle->IsThrottled()) |
| 139 | throttle->Unthrottle(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 144 | throttle_new_requests_ = throttle_new_requests; |
| 145 | } |
| 146 | |
| 147 | // Includes both throttled and unthrottled throttles. |
| 148 | size_t num_outstanding_requests() const { |
| 149 | return outstanding_throttles_.size(); |
| 150 | } |
| 151 | |
| 152 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 153 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 154 | void set_priority_change_closure( |
| 155 | const base::Closure& priority_change_closure) { |
| 156 | priority_change_closure_ = priority_change_closure; |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 161 | public: |
| 162 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 163 | |
| 164 | // Throttle |
| 165 | bool IsThrottled() const override { return throttled_; } |
| 166 | void SetPriority(RequestPriority priority) override { |
| 167 | throttler_->SetPriorityCalled(priority); |
| 168 | } |
| 169 | |
| 170 | TestThrottle(bool throttled, |
| 171 | ThrottleDelegate* delegate, |
| 172 | TestNetworkStreamThrottler* throttler) |
| 173 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 174 | |
| 175 | void Unthrottle() { |
| 176 | EXPECT_TRUE(throttled_); |
| 177 | |
| 178 | throttled_ = false; |
| 179 | delegate_->OnThrottleStateChanged(); |
| 180 | } |
| 181 | |
| 182 | bool throttled_; |
| 183 | ThrottleDelegate* delegate_; |
| 184 | TestNetworkStreamThrottler* throttler_; |
| 185 | }; |
| 186 | |
| 187 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 188 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 189 | outstanding_throttles_.erase(throttle); |
| 190 | } |
| 191 | |
| 192 | void SetPriorityCalled(RequestPriority priority) { |
| 193 | ++num_set_priority_calls_; |
| 194 | last_priority_set_ = priority; |
| 195 | if (!priority_change_closure_.is_null()) |
| 196 | priority_change_closure_.Run(); |
| 197 | } |
| 198 | |
| 199 | // Includes both throttled and unthrottled throttles. |
| 200 | std::set<TestThrottle*> outstanding_throttles_; |
| 201 | bool throttle_new_requests_; |
| 202 | int num_set_priority_calls_; |
| 203 | RequestPriority last_priority_set_; |
| 204 | base::Closure priority_change_closure_; |
| 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 207 | }; |
| 208 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 209 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 210 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 211 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 212 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 213 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 214 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 215 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 216 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 217 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 218 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 219 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 220 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 221 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 222 | const char kAlternativeServiceHttpHeader[] = |
| 223 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 224 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 226 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 227 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 228 | } |
| 229 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 230 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 231 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 232 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 233 | } |
| 234 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 236 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 237 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 240 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 241 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 242 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 243 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 244 | if (!params) |
| 245 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 246 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 247 | if (!params->GetList("headers", &header_list)) |
| 248 | return false; |
| 249 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 250 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 251 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 255 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 256 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 257 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 258 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 259 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 260 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 262 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 263 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 264 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 265 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | |
| 267 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 268 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 269 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 270 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 271 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | } |
| 274 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 275 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 276 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 277 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 278 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 279 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 280 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 281 | |
| 282 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 283 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 284 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 285 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 286 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 287 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 288 | load_timing_info.send_start); |
| 289 | |
| 290 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 291 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 292 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 294 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 295 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 299 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 300 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 301 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 302 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 303 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 304 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 305 | |
| 306 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 307 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 308 | load_timing_info.proxy_resolve_end); |
| 309 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 310 | load_timing_info.send_start); |
| 311 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 312 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 313 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 314 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 315 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 316 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 320 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 321 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 322 | int connect_timing_flags) { |
| 323 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 324 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 325 | |
| 326 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 327 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 328 | load_timing_info.proxy_resolve_end); |
| 329 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 330 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 331 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 332 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 333 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 334 | load_timing_info.send_start); |
| 335 | |
| 336 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 337 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 338 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 339 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 340 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 341 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 342 | } |
| 343 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 344 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 345 | headers->SetHeader("Connection", "Upgrade"); |
| 346 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 347 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 348 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 349 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 350 | } |
| 351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 352 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 353 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 354 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 355 | } |
| 356 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame^] | 357 | // Note that the pointer written into |*throttler| will only be valid |
| 358 | // for the lifetime of the returned HttpNetworkSession. |
| 359 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 360 | SpdySessionDependencies* session_deps, |
| 361 | TestNetworkStreamThrottler** throttler) { |
| 362 | std::unique_ptr<HttpNetworkSession> session( |
| 363 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 364 | |
| 365 | std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( |
| 366 | new TestNetworkStreamThrottler); |
| 367 | *throttler = owned_throttler.get(); |
| 368 | |
| 369 | HttpNetworkSessionPeer peer(session.get()); |
| 370 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 371 | |
| 372 | return session; |
| 373 | } |
| 374 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 375 | } // namespace |
| 376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 377 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 378 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 379 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 380 | // Important to restore the per-pool limit first, since the pool limit must |
| 381 | // always be greater than group limit, and the tests reduce both limits. |
| 382 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 383 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 384 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 385 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 386 | } |
| 387 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 388 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 389 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 390 | : ssl_(ASYNC, OK), |
| 391 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 392 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 393 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 394 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 395 | session_deps_.enable_http2_alternative_service_with_different_host = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 396 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 397 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 398 | struct SimpleGetHelperResult { |
| 399 | int rv; |
| 400 | std::string status_line; |
| 401 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 402 | int64_t total_received_bytes; |
| 403 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 404 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 405 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 406 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 407 | }; |
| 408 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 409 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 410 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 411 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 412 | } |
| 413 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 414 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 415 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 416 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 417 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 418 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 419 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 420 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 421 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 422 | } |
| 423 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 424 | // Either |write_failure| specifies a write failure or |read_failure| |
| 425 | // specifies a read failure when using a reused socket. In either case, the |
| 426 | // failure should cause the network transaction to resend the request, and the |
| 427 | // other argument should be NULL. |
| 428 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 429 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 430 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 431 | // Either |write_failure| specifies a write failure or |read_failure| |
| 432 | // specifies a read failure when using a reused socket. In either case, the |
| 433 | // failure should cause the network transaction to resend the request, and the |
| 434 | // other argument should be NULL. |
| 435 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 436 | const MockRead* read_failure, |
| 437 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 438 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 439 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 440 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 441 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 442 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 443 | HttpRequestInfo request; |
| 444 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 445 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 446 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 447 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 448 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 450 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 451 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 452 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 453 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 454 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 456 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 457 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 458 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 459 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 462 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 463 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 464 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 465 | |
| 466 | // Even in the failure cases that use this function, connections are always |
| 467 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 468 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 469 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 470 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | if (out.rv != OK) |
| 472 | return out; |
| 473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 475 | // Can't use ASSERT_* inside helper functions like this, so |
| 476 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 477 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 478 | out.rv = ERR_UNEXPECTED; |
| 479 | return out; |
| 480 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 481 | out.status_line = response->headers->GetStatusLine(); |
| 482 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 483 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 484 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 485 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 486 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 488 | EXPECT_EQ(got_endpoint, |
| 489 | out.remote_endpoint_after_start.address().size() > 0); |
| 490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 491 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 493 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 494 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 495 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 496 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 497 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 498 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 499 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 500 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 501 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 502 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 503 | std::string line; |
| 504 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 505 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 506 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 507 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 509 | std::string value; |
| 510 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 511 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 512 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 513 | EXPECT_EQ("keep-alive", value); |
| 514 | |
| 515 | std::string response_headers; |
| 516 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 517 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 518 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 520 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 521 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 522 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 524 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 525 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 526 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 527 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 528 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 529 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 530 | MockWrite data_writes[] = { |
| 531 | MockWrite("GET / HTTP/1.1\r\n" |
| 532 | "Host: www.example.org\r\n" |
| 533 | "Connection: keep-alive\r\n\r\n"), |
| 534 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 535 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 537 | arraysize(data_writes)); |
| 538 | StaticSocketDataProvider* data[] = {&reads}; |
| 539 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 540 | |
| 541 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 542 | out.total_sent_bytes); |
| 543 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 544 | } |
| 545 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 546 | void AddSSLSocketData() { |
| 547 | ssl_.next_proto = kProtoHTTP2; |
| 548 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 549 | ASSERT_TRUE(ssl_.cert); |
| 550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 551 | } |
| 552 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 553 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 554 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 555 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 556 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 557 | |
| 558 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 559 | |
| 560 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 561 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 562 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 563 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 564 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 565 | |
| 566 | // Original socket limits. Some tests set these. Safest to always restore |
| 567 | // them once each test has been run. |
| 568 | int old_max_group_sockets_; |
| 569 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 570 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 571 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 572 | namespace { |
| 573 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 574 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 575 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 576 | BeforeHeadersSentHandler() |
| 577 | : observed_before_headers_sent_with_proxy_(false), |
| 578 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 579 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 580 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 581 | HttpRequestHeaders* request_headers) { |
| 582 | observed_before_headers_sent_ = true; |
| 583 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 584 | !proxy_info.is_quic()) { |
| 585 | return; |
| 586 | } |
| 587 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 588 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 589 | } |
| 590 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 591 | bool observed_before_headers_sent_with_proxy() const { |
| 592 | return observed_before_headers_sent_with_proxy_; |
| 593 | } |
| 594 | |
| 595 | bool observed_before_headers_sent() const { |
| 596 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | std::string observed_proxy_server_uri() const { |
| 600 | return observed_proxy_server_uri_; |
| 601 | } |
| 602 | |
| 603 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 604 | bool observed_before_headers_sent_with_proxy_; |
| 605 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 606 | std::string observed_proxy_server_uri_; |
| 607 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 608 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 609 | }; |
| 610 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 611 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 612 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 613 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 614 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 615 | const int sizeof_row = strlen(row); |
| 616 | const int num_rows = static_cast<int>( |
| 617 | ceil(static_cast<float>(size) / sizeof_row)); |
| 618 | const int sizeof_data = num_rows * sizeof_row; |
| 619 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 620 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 621 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 622 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 623 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 624 | } |
| 625 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 626 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 627 | // Alternative functions that eliminate randomness and dependency on the local |
| 628 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 629 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 630 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 631 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 632 | static size_t current_byte = 0; |
| 633 | for (size_t i = 0; i < n; ++i) { |
| 634 | output[i] = bytes[current_byte++]; |
| 635 | current_byte %= arraysize(bytes); |
| 636 | } |
| 637 | } |
| 638 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 639 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 640 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 641 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 642 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 643 | static size_t current_byte = 0; |
| 644 | for (size_t i = 0; i < n; ++i) { |
| 645 | output[i] = bytes[current_byte++]; |
| 646 | current_byte %= arraysize(bytes); |
| 647 | } |
| 648 | } |
| 649 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 650 | std::string MockGetHostName() { |
| 651 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 652 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 653 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 654 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 655 | template<typename ParentPool> |
| 656 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 657 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 658 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 659 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 660 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 661 | const std::string last_group_name_received() const { |
| 662 | return last_group_name_; |
| 663 | } |
| 664 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 665 | int RequestSocket(const std::string& group_name, |
| 666 | const void* socket_params, |
| 667 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 668 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 669 | ClientSocketHandle* handle, |
| 670 | const CompletionCallback& callback, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 671 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 672 | last_group_name_ = group_name; |
| 673 | return ERR_IO_PENDING; |
| 674 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 675 | void CancelRequest(const std::string& group_name, |
| 676 | ClientSocketHandle* handle) override {} |
| 677 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 678 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | int id) override {} |
| 680 | void CloseIdleSockets() override {} |
| 681 | int IdleSocketCount() const override { return 0; } |
| 682 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 683 | return 0; |
| 684 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 685 | LoadState GetLoadState(const std::string& group_name, |
| 686 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 687 | return LOAD_STATE_IDLE; |
| 688 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 690 | return base::TimeDelta(); |
| 691 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 692 | |
| 693 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 694 | std::string last_group_name_; |
| 695 | }; |
| 696 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 697 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 698 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 699 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 700 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 701 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 702 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 703 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 704 | CaptureGroupNameSSLSocketPool; |
| 705 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 706 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 707 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 708 | HostResolver* host_resolver, |
| 709 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 710 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 711 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 712 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 713 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 714 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 715 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 716 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 717 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 718 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 719 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 720 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 721 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 722 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 723 | : SSLClientSocketPool(0, |
| 724 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 725 | cert_verifier, |
| 726 | NULL, |
| 727 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 728 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 729 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 730 | std::string(), |
| 731 | NULL, |
| 732 | NULL, |
| 733 | NULL, |
| 734 | NULL, |
| 735 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 736 | NULL) { |
| 737 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 738 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 739 | //----------------------------------------------------------------------------- |
| 740 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 741 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 742 | // configured for common cases. |
| 743 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 744 | if (!auth_challenge) |
| 745 | return false; |
| 746 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 747 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 748 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 749 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 750 | return true; |
| 751 | } |
| 752 | |
| 753 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 754 | if (!auth_challenge) |
| 755 | return false; |
| 756 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 757 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 758 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 759 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 760 | return true; |
| 761 | } |
| 762 | |
| 763 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 764 | if (!auth_challenge) |
| 765 | return false; |
| 766 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 767 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 769 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 770 | return true; |
| 771 | } |
| 772 | |
| 773 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 774 | if (!auth_challenge) |
| 775 | return false; |
| 776 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 777 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 778 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 779 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 780 | return true; |
| 781 | } |
| 782 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 783 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 785 | if (!auth_challenge) |
| 786 | return false; |
| 787 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 788 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 790 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 791 | return true; |
| 792 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 793 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 794 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 795 | } // namespace |
| 796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 797 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 800 | } |
| 801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 802 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 803 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 804 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 805 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 806 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 808 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 809 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 810 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 811 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 812 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 813 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 814 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 815 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 816 | |
| 817 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 821 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 822 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 823 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 826 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 827 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 828 | EXPECT_THAT(out.rv, IsOk()); |
| 829 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 830 | EXPECT_EQ("hello world", out.response_data); |
| 831 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 832 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 833 | } |
| 834 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 835 | // Response with no status line, and a weird port. Should fail by default. |
| 836 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 837 | MockRead data_reads[] = { |
| 838 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 839 | }; |
| 840 | |
| 841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 843 | |
| 844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 845 | |
| 846 | std::unique_ptr<HttpTransaction> trans( |
| 847 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 848 | |
| 849 | HttpRequestInfo request; |
| 850 | request.method = "GET"; |
| 851 | request.url = GURL("http://www.example.com:2000/"); |
| 852 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 853 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 854 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 855 | } |
| 856 | |
| 857 | // Response with no status line, and a weird port. Option to allow weird ports |
| 858 | // enabled. |
| 859 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 860 | MockRead data_reads[] = { |
| 861 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 862 | }; |
| 863 | |
| 864 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 865 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 866 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 868 | |
| 869 | std::unique_ptr<HttpTransaction> trans( |
| 870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 871 | |
| 872 | HttpRequestInfo request; |
| 873 | request.method = "GET"; |
| 874 | request.url = GURL("http://www.example.com:2000/"); |
| 875 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 876 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 877 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 878 | |
| 879 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 880 | ASSERT_TRUE(info->headers); |
| 881 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 882 | |
| 883 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 884 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 885 | } |
| 886 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 887 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 888 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 889 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 890 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 891 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 892 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 894 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 895 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 896 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 897 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 898 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 899 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 903 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 904 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 905 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 906 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 907 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 908 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 909 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 910 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 912 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 913 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 914 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 918 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 920 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 921 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 923 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 924 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 925 | EXPECT_THAT(out.rv, IsOk()); |
| 926 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 927 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 928 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 929 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 933 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 935 | MockRead("\n"), |
| 936 | MockRead("\n"), |
| 937 | MockRead("Q"), |
| 938 | MockRead("J"), |
| 939 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 942 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 943 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 944 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 945 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 946 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 947 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 948 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 952 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 954 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 955 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 957 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 958 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 959 | EXPECT_THAT(out.rv, IsOk()); |
| 960 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 961 | EXPECT_EQ("HTT", out.response_data); |
| 962 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 963 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 964 | } |
| 965 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 966 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 967 | // persistent connection. The response should still terminate since a 204 |
| 968 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 969 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 970 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 971 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 972 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 973 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 974 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 975 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 976 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 977 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 978 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 979 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 980 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 981 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 982 | int64_t response_size = reads_size - strlen(junk); |
| 983 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 986 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 987 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 988 | std::string final_chunk = "0\r\n\r\n"; |
| 989 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 990 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 991 | MockRead data_reads[] = { |
| 992 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 993 | MockRead("5\r\nHello\r\n"), |
| 994 | MockRead("1\r\n"), |
| 995 | MockRead(" \r\n"), |
| 996 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 997 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 999 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1000 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1001 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1002 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1003 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1004 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1005 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1006 | int64_t response_size = reads_size - extra_data.size(); |
| 1007 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1008 | } |
| 1009 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1010 | // Next tests deal with http://crbug.com/56344. |
| 1011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1012 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1013 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1014 | MockRead data_reads[] = { |
| 1015 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1016 | MockRead("Content-Length: 10\r\n"), |
| 1017 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1018 | }; |
| 1019 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1020 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1021 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1022 | } |
| 1023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1024 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1025 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1026 | MockRead data_reads[] = { |
| 1027 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1028 | MockRead("Content-Length: 5\r\n"), |
| 1029 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1030 | MockRead("Hello"), |
| 1031 | }; |
| 1032 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1033 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1034 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1035 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1036 | EXPECT_EQ("Hello", out.response_data); |
| 1037 | } |
| 1038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1039 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1040 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1041 | // More than 2 dupes. |
| 1042 | { |
| 1043 | MockRead data_reads[] = { |
| 1044 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1045 | MockRead("Content-Length: 5\r\n"), |
| 1046 | MockRead("Content-Length: 5\r\n"), |
| 1047 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1048 | MockRead("Hello"), |
| 1049 | }; |
| 1050 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1051 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1052 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1053 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1054 | EXPECT_EQ("Hello", out.response_data); |
| 1055 | } |
| 1056 | // HTTP/1.0 |
| 1057 | { |
| 1058 | MockRead data_reads[] = { |
| 1059 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1060 | MockRead("Content-Length: 5\r\n"), |
| 1061 | MockRead("Content-Length: 5\r\n"), |
| 1062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1063 | MockRead("Hello"), |
| 1064 | }; |
| 1065 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1066 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1067 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1068 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1069 | EXPECT_EQ("Hello", out.response_data); |
| 1070 | } |
| 1071 | // 2 dupes and one mismatched. |
| 1072 | { |
| 1073 | MockRead data_reads[] = { |
| 1074 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1075 | MockRead("Content-Length: 10\r\n"), |
| 1076 | MockRead("Content-Length: 10\r\n"), |
| 1077 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1078 | }; |
| 1079 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1080 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1081 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1085 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1086 | MultipleContentLengthHeadersTransferEncoding) { |
| 1087 | MockRead data_reads[] = { |
| 1088 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1089 | MockRead("Content-Length: 666\r\n"), |
| 1090 | MockRead("Content-Length: 1337\r\n"), |
| 1091 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1092 | MockRead("5\r\nHello\r\n"), |
| 1093 | MockRead("1\r\n"), |
| 1094 | MockRead(" \r\n"), |
| 1095 | MockRead("5\r\nworld\r\n"), |
| 1096 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1097 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1098 | }; |
| 1099 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1100 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1101 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1102 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1103 | EXPECT_EQ("Hello world", out.response_data); |
| 1104 | } |
| 1105 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1106 | // Next tests deal with http://crbug.com/98895. |
| 1107 | |
| 1108 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1109 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | MockRead data_reads[] = { |
| 1111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1112 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"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] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1119 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1120 | EXPECT_EQ("Hello", out.response_data); |
| 1121 | } |
| 1122 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1123 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1124 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1125 | MockRead data_reads[] = { |
| 1126 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1127 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1128 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1129 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1130 | MockRead("Hello"), |
| 1131 | }; |
| 1132 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1133 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1134 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1135 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1136 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1140 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1141 | MockRead data_reads[] = { |
| 1142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1143 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1144 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1145 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1146 | MockRead("Hello"), |
| 1147 | }; |
| 1148 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1149 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1150 | EXPECT_THAT(out.rv, |
| 1151 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | } |
| 1153 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1154 | // Checks that two identical Location headers result in no error. |
| 1155 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1156 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | MockRead data_reads[] = { |
| 1158 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1159 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1160 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1162 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1163 | }; |
| 1164 | |
| 1165 | HttpRequestInfo request; |
| 1166 | request.method = "GET"; |
| 1167 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1170 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | |
| 1172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1175 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1177 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1180 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1183 | ASSERT_TRUE(response); |
| 1184 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1185 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1186 | std::string url; |
| 1187 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1188 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1189 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1193 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | MockRead data_reads[] = { |
| 1195 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1196 | MockRead("Location: http://good.com/\r\n"), |
| 1197 | MockRead("Location: http://evil.com/\r\n"), |
| 1198 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1199 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | }; |
| 1201 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1202 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1203 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1204 | } |
| 1205 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1206 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1207 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1208 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1209 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1210 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1211 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1215 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1216 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1217 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1218 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1219 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1221 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1222 | "Host: www.example.org\r\n" |
| 1223 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | }; |
| 1225 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1226 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1227 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1229 | // No response body because the test stops reading here. |
| 1230 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1231 | }; |
| 1232 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1233 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1234 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1235 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1237 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1238 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1239 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | |
| 1242 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1243 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1245 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1246 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | |
| 1248 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1249 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1250 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1251 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1252 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1253 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1254 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | |
| 1256 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1257 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | bool has_server_header = response->headers->EnumerateHeader( |
| 1259 | &iter, "Server", &server_header); |
| 1260 | EXPECT_TRUE(has_server_header); |
| 1261 | EXPECT_EQ("Blah", server_header); |
| 1262 | |
| 1263 | // Reading should give EOF right away, since there is no message body |
| 1264 | // (despite non-zero content-length). |
| 1265 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1266 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1268 | EXPECT_EQ("", response_data); |
| 1269 | } |
| 1270 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1271 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1272 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1273 | |
| 1274 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1275 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1276 | MockRead("hello"), |
| 1277 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1278 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1279 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1280 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1281 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1282 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1283 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1284 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1285 | "hello", "world" |
| 1286 | }; |
| 1287 | |
| 1288 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1289 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1291 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1295 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1297 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | |
| 1300 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1301 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1304 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1306 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1307 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1308 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
| 1310 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1312 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1313 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1317 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1318 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1319 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1320 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1321 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1322 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1323 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | request.method = "POST"; |
| 1325 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1326 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1328 | // Check the upload progress returned before initialization is correct. |
| 1329 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1330 | EXPECT_EQ(0u, progress.size()); |
| 1331 | EXPECT_EQ(0u, progress.position()); |
| 1332 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1335 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1337 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1338 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1339 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1340 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1342 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1345 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1347 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
| 1350 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1351 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1354 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1356 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1357 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
| 1359 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1360 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1361 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1362 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | } |
| 1364 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1365 | // This test is almost the same as Ignores100 above, but the response contains |
| 1366 | // 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] | 1367 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1368 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1369 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1370 | request.method = "GET"; |
| 1371 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1372 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1374 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1375 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1376 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1377 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1378 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1379 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1380 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1382 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1383 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1385 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1387 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | |
| 1390 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1393 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1394 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1396 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1398 | |
| 1399 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1400 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1401 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | EXPECT_EQ("hello world", response_data); |
| 1403 | } |
| 1404 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1405 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1406 | HttpRequestInfo request; |
| 1407 | request.method = "POST"; |
| 1408 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1412 | |
| 1413 | MockRead data_reads[] = { |
| 1414 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1415 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1416 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1417 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1418 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1419 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1420 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1421 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1422 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1424 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1425 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1427 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1428 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1429 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1430 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1431 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1432 | } |
| 1433 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1434 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1435 | HttpRequestInfo request; |
| 1436 | request.method = "POST"; |
| 1437 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1438 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1441 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1442 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1443 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1444 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1445 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1448 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1449 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1450 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1452 | |
| 1453 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1454 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1455 | } |
| 1456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1457 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1458 | const MockWrite* write_failure, |
| 1459 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1460 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1461 | request.method = "GET"; |
| 1462 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1463 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1464 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1465 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1467 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1468 | // Written data for successfully sending both requests. |
| 1469 | MockWrite data1_writes[] = { |
| 1470 | MockWrite("GET / HTTP/1.1\r\n" |
| 1471 | "Host: www.foo.com\r\n" |
| 1472 | "Connection: keep-alive\r\n\r\n"), |
| 1473 | MockWrite("GET / HTTP/1.1\r\n" |
| 1474 | "Host: www.foo.com\r\n" |
| 1475 | "Connection: keep-alive\r\n\r\n") |
| 1476 | }; |
| 1477 | |
| 1478 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1479 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1480 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1481 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1482 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1484 | |
| 1485 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1486 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1487 | data1_writes[1] = *write_failure; |
| 1488 | } else { |
| 1489 | ASSERT_TRUE(read_failure); |
| 1490 | data1_reads[2] = *read_failure; |
| 1491 | } |
| 1492 | |
| 1493 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1494 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1495 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1496 | |
| 1497 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1498 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1499 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1500 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1501 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1502 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1503 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1504 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1505 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1506 | "hello", "world" |
| 1507 | }; |
| 1508 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1509 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1510 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1511 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1512 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1514 | |
tfarina | 42834111 | 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)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1517 | |
| 1518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1519 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1520 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1521 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1522 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1523 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1524 | if (i == 0) { |
| 1525 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1526 | } else { |
| 1527 | // The second request should be using a new socket. |
| 1528 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1529 | } |
| 1530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1531 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1532 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1533 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1534 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1535 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1536 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1537 | |
| 1538 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1539 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1541 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1542 | } |
| 1543 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1544 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1545 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1546 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1547 | const MockRead* read_failure, |
| 1548 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1549 | HttpRequestInfo request; |
| 1550 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1551 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1552 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1553 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1554 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1557 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1558 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1559 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1560 | ssl1.next_proto = kProtoHTTP2; |
| 1561 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1562 | } |
| 1563 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1565 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1566 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1567 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1568 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1569 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1570 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1571 | SpdySerializedFrame spdy_data( |
| 1572 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1573 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1574 | // HTTP/1.1 versions of the request and response. |
| 1575 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1576 | "Host: www.foo.com\r\n" |
| 1577 | "Connection: keep-alive\r\n\r\n"; |
| 1578 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1579 | const char kHttpData[] = "hello"; |
| 1580 | |
| 1581 | std::vector<MockRead> data1_reads; |
| 1582 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1583 | if (write_failure) { |
| 1584 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1585 | data1_writes.push_back(*write_failure); |
| 1586 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | } else { |
| 1588 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1589 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1590 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1591 | } else { |
| 1592 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1593 | } |
| 1594 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1595 | } |
| 1596 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1597 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1598 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1599 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1600 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1601 | std::vector<MockRead> data2_reads; |
| 1602 | std::vector<MockWrite> data2_writes; |
| 1603 | |
| 1604 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1605 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1606 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1607 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1608 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1609 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1610 | } else { |
| 1611 | data2_writes.push_back( |
| 1612 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1613 | |
| 1614 | data2_reads.push_back( |
| 1615 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1616 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1617 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1618 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1619 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1620 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1621 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1622 | |
| 1623 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1624 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1625 | // Wait for the preconnect to complete. |
| 1626 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1627 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1628 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1629 | |
| 1630 | // Make the request. |
| 1631 | TestCompletionCallback callback; |
| 1632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1634 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1637 | |
| 1638 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1639 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1640 | |
| 1641 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1642 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1643 | TestLoadTimingNotReused( |
| 1644 | load_timing_info, |
| 1645 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1647 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1648 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1649 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1650 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1651 | if (response->was_fetched_via_spdy) { |
| 1652 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1653 | } else { |
| 1654 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1655 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1656 | |
| 1657 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1658 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1660 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1661 | } |
| 1662 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1663 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1664 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1665 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1666 | } |
| 1667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1668 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1669 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1670 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1671 | } |
| 1672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1673 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1674 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1675 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1676 | } |
| 1677 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1678 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1679 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1680 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1681 | MockRead read_failure(SYNCHRONOUS, |
| 1682 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1683 | "Connection: Keep-Alive\r\n" |
| 1684 | "Content-Length: 6\r\n\r\n" |
| 1685 | "Pickle"); |
| 1686 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1687 | } |
| 1688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1689 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1690 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1691 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1692 | } |
| 1693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1694 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1695 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1696 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1697 | } |
| 1698 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1699 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1700 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1701 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1702 | } |
| 1703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1704 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1705 | MockRead read_failure(ASYNC, OK); // EOF |
| 1706 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1707 | } |
| 1708 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1709 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1710 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1711 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1712 | MockRead read_failure(SYNCHRONOUS, |
| 1713 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1714 | "Connection: Keep-Alive\r\n" |
| 1715 | "Content-Length: 6\r\n\r\n" |
| 1716 | "Pickle"); |
| 1717 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1718 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1719 | } |
| 1720 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1721 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1722 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1723 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1724 | } |
| 1725 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1726 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1727 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1728 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1729 | } |
| 1730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1731 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1732 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1733 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1734 | } |
| 1735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1736 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1737 | MockRead read_failure(ASYNC, OK); // EOF |
| 1738 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1739 | } |
| 1740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1742 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1744 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1745 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1746 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1747 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1748 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1749 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1750 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1751 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1752 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1753 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1754 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1755 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1758 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1759 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1760 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1762 | |
| 1763 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1764 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1765 | |
| 1766 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1767 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1768 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | // What do various browsers do when the server closes a non-keepalive |
| 1772 | // connection without sending any response header or body? |
| 1773 | // |
| 1774 | // IE7: error page |
| 1775 | // Safari 3.1.2 (Windows): error page |
| 1776 | // Firefox 3.0.1: blank page |
| 1777 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1778 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1779 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1780 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1781 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1782 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1783 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1784 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1785 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1786 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1787 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1788 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1789 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1790 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1791 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1792 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1793 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1794 | // destructor in such situations. |
| 1795 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1796 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1797 | HttpRequestInfo request; |
| 1798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1799 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1800 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1802 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1803 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | |
| 1805 | MockRead data_reads[] = { |
| 1806 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1807 | MockRead("Connection: keep-alive\r\n"), |
| 1808 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1809 | MockRead("hello"), |
| 1810 | MockRead(SYNCHRONOUS, 0), |
| 1811 | }; |
| 1812 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1814 | |
| 1815 | TestCompletionCallback callback; |
| 1816 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1817 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1819 | |
| 1820 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1822 | |
| 1823 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1824 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1825 | if (rv == ERR_IO_PENDING) |
| 1826 | rv = callback.WaitForResult(); |
| 1827 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1828 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1829 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1830 | |
| 1831 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1832 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1833 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1834 | } |
| 1835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1836 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1837 | HttpRequestInfo request; |
| 1838 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1839 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1840 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1841 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1842 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1843 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1844 | |
| 1845 | MockRead data_reads[] = { |
| 1846 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1847 | MockRead("Connection: keep-alive\r\n"), |
| 1848 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1849 | MockRead(SYNCHRONOUS, 0), |
| 1850 | }; |
| 1851 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1853 | |
| 1854 | TestCompletionCallback callback; |
| 1855 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1856 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1858 | |
| 1859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1861 | |
| 1862 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1863 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | if (rv == ERR_IO_PENDING) |
| 1865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1867 | |
| 1868 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1869 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1870 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1871 | } |
| 1872 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1873 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1874 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1875 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1876 | HttpRequestInfo request; |
| 1877 | request.method = "GET"; |
| 1878 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1879 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1880 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1881 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1883 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1884 | const char* request_data = |
| 1885 | "GET / HTTP/1.1\r\n" |
| 1886 | "Host: www.foo.com\r\n" |
| 1887 | "Connection: keep-alive\r\n\r\n"; |
| 1888 | MockWrite data_writes[] = { |
| 1889 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1890 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1891 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1892 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1893 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1894 | }; |
| 1895 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1896 | // Note that because all these reads happen in the same |
| 1897 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1898 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1899 | MockRead data_reads[] = { |
| 1900 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1901 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1902 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1903 | MockRead(ASYNC, 7, |
| 1904 | "HTTP/1.1 302 Found\r\n" |
| 1905 | "Content-Length: 0\r\n\r\n"), |
| 1906 | MockRead(ASYNC, 9, |
| 1907 | "HTTP/1.1 302 Found\r\n" |
| 1908 | "Content-Length: 5\r\n\r\n" |
| 1909 | "hello"), |
| 1910 | MockRead(ASYNC, 11, |
| 1911 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1912 | "Content-Length: 0\r\n\r\n"), |
| 1913 | MockRead(ASYNC, 13, |
| 1914 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1915 | "Content-Length: 5\r\n\r\n" |
| 1916 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1917 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1918 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1919 | // the set_busy_before_sync_reads(true) call, while the |
| 1920 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1921 | // reuseable. See http://crbug.com/544255. |
| 1922 | MockRead(ASYNC, 15, |
| 1923 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1924 | "Content-Length: 5\r\n\r\n"), |
| 1925 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1926 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1927 | MockRead(ASYNC, 18, |
| 1928 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1929 | "Content-Length: 5\r\n\r\n" |
| 1930 | "he"), |
| 1931 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1932 | |
| 1933 | // The body of the final request is actually read. |
| 1934 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1935 | MockRead(ASYNC, 22, "hello"), |
| 1936 | }; |
| 1937 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1938 | arraysize(data_writes)); |
| 1939 | data.set_busy_before_sync_reads(true); |
| 1940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1941 | |
| 1942 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1943 | std::string response_lines[kNumUnreadBodies]; |
| 1944 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1945 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1946 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1947 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1949 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1950 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1951 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1952 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1953 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1954 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1955 | LoadTimingInfo load_timing_info; |
| 1956 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1957 | if (i == 0) { |
| 1958 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1959 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1960 | } else { |
| 1961 | TestLoadTimingReused(load_timing_info); |
| 1962 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1963 | } |
| 1964 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1965 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1966 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1967 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1968 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1969 | response_lines[i] = response->headers->GetStatusLine(); |
| 1970 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1971 | // Delete the transaction without reading the response bodies. Then spin |
| 1972 | // the message loop, so the response bodies are drained. |
| 1973 | trans.reset(); |
| 1974 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1975 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1976 | |
| 1977 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1978 | "HTTP/1.1 204 No Content", |
| 1979 | "HTTP/1.1 205 Reset Content", |
| 1980 | "HTTP/1.1 304 Not Modified", |
| 1981 | "HTTP/1.1 302 Found", |
| 1982 | "HTTP/1.1 302 Found", |
| 1983 | "HTTP/1.1 301 Moved Permanently", |
| 1984 | "HTTP/1.1 301 Moved Permanently", |
| 1985 | "HTTP/1.1 200 Hunky-Dory", |
| 1986 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1987 | }; |
| 1988 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1989 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1990 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1991 | |
| 1992 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1993 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1995 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1996 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1997 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1998 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2000 | ASSERT_TRUE(response); |
| 2001 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2002 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2004 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2006 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2007 | } |
| 2008 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2009 | // Sockets that receive extra data after a response is complete should not be |
| 2010 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2011 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2013 | MockWrite data_writes1[] = { |
| 2014 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2015 | "Host: www.borked.com\r\n" |
| 2016 | "Connection: keep-alive\r\n\r\n"), |
| 2017 | }; |
| 2018 | |
| 2019 | MockRead data_reads1[] = { |
| 2020 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2021 | "Connection: keep-alive\r\n" |
| 2022 | "Content-Length: 22\r\n\r\n" |
| 2023 | "This server is borked."), |
| 2024 | }; |
| 2025 | |
| 2026 | MockWrite data_writes2[] = { |
| 2027 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2028 | "Host: www.borked.com\r\n" |
| 2029 | "Connection: keep-alive\r\n\r\n"), |
| 2030 | }; |
| 2031 | |
| 2032 | MockRead data_reads2[] = { |
| 2033 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2034 | "Content-Length: 3\r\n\r\n" |
| 2035 | "foo"), |
| 2036 | }; |
| 2037 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2038 | data_writes1, arraysize(data_writes1)); |
| 2039 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2040 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2041 | data_writes2, arraysize(data_writes2)); |
| 2042 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2043 | |
| 2044 | TestCompletionCallback callback; |
| 2045 | HttpRequestInfo request1; |
| 2046 | request1.method = "HEAD"; |
| 2047 | request1.url = GURL("http://www.borked.com/"); |
| 2048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2049 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2051 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2052 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2053 | |
| 2054 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2055 | ASSERT_TRUE(response1); |
| 2056 | ASSERT_TRUE(response1->headers); |
| 2057 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2058 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2059 | |
| 2060 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2061 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2062 | EXPECT_EQ("", response_data1); |
| 2063 | // Deleting the transaction attempts to release the socket back into the |
| 2064 | // socket pool. |
| 2065 | trans1.reset(); |
| 2066 | |
| 2067 | HttpRequestInfo request2; |
| 2068 | request2.method = "GET"; |
| 2069 | request2.url = GURL("http://www.borked.com/foo"); |
| 2070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2071 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2073 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2074 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2075 | |
| 2076 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2077 | ASSERT_TRUE(response2); |
| 2078 | ASSERT_TRUE(response2->headers); |
| 2079 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2080 | |
| 2081 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2082 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2083 | EXPECT_EQ("foo", response_data2); |
| 2084 | } |
| 2085 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2086 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2088 | MockWrite data_writes1[] = { |
| 2089 | MockWrite("GET / HTTP/1.1\r\n" |
| 2090 | "Host: www.borked.com\r\n" |
| 2091 | "Connection: keep-alive\r\n\r\n"), |
| 2092 | }; |
| 2093 | |
| 2094 | MockRead data_reads1[] = { |
| 2095 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2096 | "Connection: keep-alive\r\n" |
| 2097 | "Content-Length: 22\r\n\r\n" |
| 2098 | "This server is borked." |
| 2099 | "Bonus data!"), |
| 2100 | }; |
| 2101 | |
| 2102 | MockWrite data_writes2[] = { |
| 2103 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2104 | "Host: www.borked.com\r\n" |
| 2105 | "Connection: keep-alive\r\n\r\n"), |
| 2106 | }; |
| 2107 | |
| 2108 | MockRead data_reads2[] = { |
| 2109 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2110 | "Content-Length: 3\r\n\r\n" |
| 2111 | "foo"), |
| 2112 | }; |
| 2113 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2114 | data_writes1, arraysize(data_writes1)); |
| 2115 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2116 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2117 | data_writes2, arraysize(data_writes2)); |
| 2118 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2119 | |
| 2120 | TestCompletionCallback callback; |
| 2121 | HttpRequestInfo request1; |
| 2122 | request1.method = "GET"; |
| 2123 | request1.url = GURL("http://www.borked.com/"); |
| 2124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2125 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2126 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2127 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2128 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2129 | |
| 2130 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2131 | ASSERT_TRUE(response1); |
| 2132 | ASSERT_TRUE(response1->headers); |
| 2133 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2134 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2135 | |
| 2136 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2137 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2138 | EXPECT_EQ("This server is borked.", response_data1); |
| 2139 | // Deleting the transaction attempts to release the socket back into the |
| 2140 | // socket pool. |
| 2141 | trans1.reset(); |
| 2142 | |
| 2143 | HttpRequestInfo request2; |
| 2144 | request2.method = "GET"; |
| 2145 | request2.url = GURL("http://www.borked.com/foo"); |
| 2146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2147 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2149 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2150 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2151 | |
| 2152 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2153 | ASSERT_TRUE(response2); |
| 2154 | ASSERT_TRUE(response2->headers); |
| 2155 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2156 | |
| 2157 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2158 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2159 | EXPECT_EQ("foo", response_data2); |
| 2160 | } |
| 2161 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2162 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2164 | MockWrite data_writes1[] = { |
| 2165 | MockWrite("GET / HTTP/1.1\r\n" |
| 2166 | "Host: www.borked.com\r\n" |
| 2167 | "Connection: keep-alive\r\n\r\n"), |
| 2168 | }; |
| 2169 | |
| 2170 | MockRead data_reads1[] = { |
| 2171 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2172 | "Connection: keep-alive\r\n" |
| 2173 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2174 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2175 | MockRead("0\r\n\r\nBonus data!"), |
| 2176 | }; |
| 2177 | |
| 2178 | MockWrite data_writes2[] = { |
| 2179 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2180 | "Host: www.borked.com\r\n" |
| 2181 | "Connection: keep-alive\r\n\r\n"), |
| 2182 | }; |
| 2183 | |
| 2184 | MockRead data_reads2[] = { |
| 2185 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2186 | "Content-Length: 3\r\n\r\n" |
| 2187 | "foo"), |
| 2188 | }; |
| 2189 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2190 | data_writes1, arraysize(data_writes1)); |
| 2191 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2192 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2193 | data_writes2, arraysize(data_writes2)); |
| 2194 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2195 | |
| 2196 | TestCompletionCallback callback; |
| 2197 | HttpRequestInfo request1; |
| 2198 | request1.method = "GET"; |
| 2199 | request1.url = GURL("http://www.borked.com/"); |
| 2200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2201 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2203 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2204 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2205 | |
| 2206 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2207 | ASSERT_TRUE(response1); |
| 2208 | ASSERT_TRUE(response1->headers); |
| 2209 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2210 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2211 | |
| 2212 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2213 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2214 | EXPECT_EQ("This server is borked.", response_data1); |
| 2215 | // Deleting the transaction attempts to release the socket back into the |
| 2216 | // socket pool. |
| 2217 | trans1.reset(); |
| 2218 | |
| 2219 | HttpRequestInfo request2; |
| 2220 | request2.method = "GET"; |
| 2221 | request2.url = GURL("http://www.borked.com/foo"); |
| 2222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2223 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2225 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2226 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2227 | |
| 2228 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2229 | ASSERT_TRUE(response2); |
| 2230 | ASSERT_TRUE(response2->headers); |
| 2231 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2232 | |
| 2233 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2234 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2235 | EXPECT_EQ("foo", response_data2); |
| 2236 | } |
| 2237 | |
| 2238 | // This is a little different from the others - it tests the case that the |
| 2239 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2240 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2241 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2242 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2244 | MockWrite data_writes1[] = { |
| 2245 | MockWrite("GET / HTTP/1.1\r\n" |
| 2246 | "Host: www.borked.com\r\n" |
| 2247 | "Connection: keep-alive\r\n\r\n"), |
| 2248 | }; |
| 2249 | |
| 2250 | MockRead data_reads1[] = { |
| 2251 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2252 | "Connection: keep-alive\r\n" |
| 2253 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2254 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2255 | MockRead("0\r\n\r\nBonus data!"), |
| 2256 | }; |
| 2257 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2258 | data_writes1, arraysize(data_writes1)); |
| 2259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2260 | |
| 2261 | TestCompletionCallback callback; |
| 2262 | HttpRequestInfo request1; |
| 2263 | request1.method = "GET"; |
| 2264 | request1.url = GURL("http://www.borked.com/"); |
| 2265 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2266 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2267 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2268 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2269 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2270 | |
| 2271 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2272 | ASSERT_TRUE(response1); |
| 2273 | ASSERT_TRUE(response1->headers); |
| 2274 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2275 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2276 | |
| 2277 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2278 | // response body. |
| 2279 | trans1.reset(); |
| 2280 | |
| 2281 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2282 | // socket can't be reused, rather than returning it to the socket pool. |
| 2283 | base::RunLoop().RunUntilIdle(); |
| 2284 | |
| 2285 | // There should be no idle sockets in the pool. |
| 2286 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2287 | } |
| 2288 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2289 | // Test the request-challenge-retry sequence for basic auth. |
| 2290 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2291 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2292 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2294 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2295 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2296 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2297 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2300 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2301 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2302 | MockWrite( |
| 2303 | "GET / HTTP/1.1\r\n" |
| 2304 | "Host: www.example.org\r\n" |
| 2305 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2306 | }; |
| 2307 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2308 | MockRead data_reads1[] = { |
| 2309 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2310 | // Give a couple authenticate options (only the middle one is actually |
| 2311 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2312 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2313 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2314 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2315 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2316 | // Large content-length -- won't matter, as connection will be reset. |
| 2317 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2318 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2319 | }; |
| 2320 | |
| 2321 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2322 | // be issuing -- the final header line contains the credentials. |
| 2323 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2324 | MockWrite( |
| 2325 | "GET / HTTP/1.1\r\n" |
| 2326 | "Host: www.example.org\r\n" |
| 2327 | "Connection: keep-alive\r\n" |
| 2328 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2329 | }; |
| 2330 | |
| 2331 | // Lastly, the server responds with the actual content. |
| 2332 | MockRead data_reads2[] = { |
| 2333 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2335 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2337 | }; |
| 2338 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2339 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2340 | data_writes1, arraysize(data_writes1)); |
| 2341 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2342 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2343 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2346 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2347 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2348 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2350 | |
| 2351 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2352 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2353 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2354 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2355 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2356 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2357 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2358 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2359 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2360 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2361 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2363 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2364 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2365 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2367 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2369 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2371 | |
| 2372 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2374 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2375 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2376 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2377 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2378 | // The load timing after restart should have a new socket ID, and times after |
| 2379 | // those of the first load timing. |
| 2380 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2381 | load_timing_info2.connect_timing.connect_start); |
| 2382 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2383 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2384 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2385 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2386 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2387 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2389 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2390 | ASSERT_TRUE(response); |
| 2391 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2392 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2393 | } |
| 2394 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2395 | // Test the request-challenge-retry sequence for basic auth. |
| 2396 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2397 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2398 | HttpRequestInfo request; |
| 2399 | request.method = "GET"; |
| 2400 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2401 | |
| 2402 | TestNetLog log; |
| 2403 | MockHostResolver* resolver = new MockHostResolver(); |
| 2404 | session_deps_.net_log = &log; |
| 2405 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2406 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2408 | |
| 2409 | resolver->rules()->ClearRules(); |
| 2410 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2411 | |
| 2412 | MockWrite data_writes1[] = { |
| 2413 | MockWrite("GET / HTTP/1.1\r\n" |
| 2414 | "Host: www.example.org\r\n" |
| 2415 | "Connection: keep-alive\r\n\r\n"), |
| 2416 | }; |
| 2417 | |
| 2418 | MockRead data_reads1[] = { |
| 2419 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2420 | // Give a couple authenticate options (only the middle one is actually |
| 2421 | // supported). |
| 2422 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2423 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2424 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2425 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2426 | // Large content-length -- won't matter, as connection will be reset. |
| 2427 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2428 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2429 | }; |
| 2430 | |
| 2431 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2432 | // be issuing -- the final header line contains the credentials. |
| 2433 | MockWrite data_writes2[] = { |
| 2434 | MockWrite("GET / HTTP/1.1\r\n" |
| 2435 | "Host: www.example.org\r\n" |
| 2436 | "Connection: keep-alive\r\n" |
| 2437 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2438 | }; |
| 2439 | |
| 2440 | // Lastly, the server responds with the actual content. |
| 2441 | MockRead data_reads2[] = { |
| 2442 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2443 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2444 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2445 | }; |
| 2446 | |
| 2447 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2448 | data_writes1, arraysize(data_writes1)); |
| 2449 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2450 | data_writes2, arraysize(data_writes2)); |
| 2451 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2452 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2453 | |
| 2454 | TestCompletionCallback callback1; |
| 2455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2456 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2457 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2458 | |
| 2459 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2460 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2461 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2462 | |
| 2463 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2464 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2465 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2466 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2468 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2469 | ASSERT_TRUE(response); |
| 2470 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2471 | |
| 2472 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2473 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2474 | ASSERT_FALSE(endpoint.address().empty()); |
| 2475 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2476 | |
| 2477 | resolver->rules()->ClearRules(); |
| 2478 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2479 | |
| 2480 | TestCompletionCallback callback2; |
| 2481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2482 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2483 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2484 | |
| 2485 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2486 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2487 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2488 | // The load timing after restart should have a new socket ID, and times after |
| 2489 | // those of the first load timing. |
| 2490 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2491 | load_timing_info2.connect_timing.connect_start); |
| 2492 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2493 | |
| 2494 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2495 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2496 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2497 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2499 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2500 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2501 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2502 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2504 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2505 | ASSERT_FALSE(endpoint.address().empty()); |
| 2506 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2507 | } |
| 2508 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2509 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2510 | HttpRequestInfo request; |
| 2511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2512 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2513 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2517 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2518 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2519 | MockWrite( |
| 2520 | "GET / HTTP/1.1\r\n" |
| 2521 | "Host: www.example.org\r\n" |
| 2522 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2523 | }; |
| 2524 | |
| 2525 | MockRead data_reads[] = { |
| 2526 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2527 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2528 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2529 | // Large content-length -- won't matter, as connection will be reset. |
| 2530 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2531 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2532 | }; |
| 2533 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2534 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2535 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2536 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2537 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2538 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2539 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2541 | |
| 2542 | rv = callback.WaitForResult(); |
| 2543 | EXPECT_EQ(0, rv); |
| 2544 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2545 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2546 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2547 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2548 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2550 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2551 | ASSERT_TRUE(response); |
| 2552 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2553 | } |
| 2554 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2555 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2556 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2557 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2558 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2559 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2560 | // reused. See http://crbug.com/544255. |
| 2561 | for (int i = 0; i < 2; ++i) { |
| 2562 | HttpRequestInfo request; |
| 2563 | request.method = "GET"; |
| 2564 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2565 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2566 | TestNetLog log; |
| 2567 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2569 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2570 | MockWrite data_writes[] = { |
| 2571 | MockWrite(ASYNC, 0, |
| 2572 | "GET / HTTP/1.1\r\n" |
| 2573 | "Host: www.example.org\r\n" |
| 2574 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2576 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2577 | // be issuing -- the final header line contains the credentials. |
| 2578 | MockWrite(ASYNC, 6, |
| 2579 | "GET / HTTP/1.1\r\n" |
| 2580 | "Host: www.example.org\r\n" |
| 2581 | "Connection: keep-alive\r\n" |
| 2582 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2583 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2584 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2585 | MockRead data_reads[] = { |
| 2586 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2587 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2588 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2589 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2590 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2591 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2592 | // Lastly, the server responds with the actual content. |
| 2593 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2594 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2595 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2596 | MockRead(ASYNC, 10, "Hello"), |
| 2597 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2598 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2599 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2600 | arraysize(data_writes)); |
| 2601 | data.set_busy_before_sync_reads(true); |
| 2602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2603 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2604 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2607 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2608 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2609 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2610 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2611 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2612 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2613 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2614 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2615 | ASSERT_TRUE(response); |
| 2616 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2617 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2618 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2620 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2621 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2622 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2623 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2624 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2625 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2626 | TestLoadTimingReused(load_timing_info2); |
| 2627 | // The load timing after restart should have the same socket ID, and times |
| 2628 | // those of the first load timing. |
| 2629 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2630 | load_timing_info2.send_start); |
| 2631 | 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] | 2632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2633 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2634 | ASSERT_TRUE(response); |
| 2635 | EXPECT_FALSE(response->auth_challenge); |
| 2636 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2637 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2638 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2639 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2640 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2641 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2642 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2643 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2644 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2645 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2649 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2650 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2651 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2652 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2653 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2654 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2656 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2657 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2658 | MockWrite("GET / HTTP/1.1\r\n" |
| 2659 | "Host: www.example.org\r\n" |
| 2660 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2662 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2663 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2664 | MockWrite("GET / HTTP/1.1\r\n" |
| 2665 | "Host: www.example.org\r\n" |
| 2666 | "Connection: keep-alive\r\n" |
| 2667 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2668 | }; |
| 2669 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2670 | MockRead data_reads1[] = { |
| 2671 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2672 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2673 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | |
| 2675 | // Lastly, the server responds with the actual content. |
| 2676 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2677 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2678 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2679 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | }; |
| 2681 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2682 | // An incorrect reconnect would cause this to be read. |
| 2683 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2684 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2685 | }; |
| 2686 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2687 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2688 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2689 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2690 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2692 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2694 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2697 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2699 | |
| 2700 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2704 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2705 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2707 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2709 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2711 | |
| 2712 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2713 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2716 | ASSERT_TRUE(response); |
| 2717 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2718 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2722 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2723 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2724 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2726 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2729 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2730 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2731 | MockWrite("GET / HTTP/1.1\r\n" |
| 2732 | "Host: www.example.org\r\n" |
| 2733 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2735 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2736 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | MockWrite("GET / HTTP/1.1\r\n" |
| 2738 | "Host: www.example.org\r\n" |
| 2739 | "Connection: keep-alive\r\n" |
| 2740 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | }; |
| 2742 | |
| 2743 | // Respond with 5 kb of response body. |
| 2744 | std::string large_body_string("Unauthorized"); |
| 2745 | large_body_string.append(5 * 1024, ' '); |
| 2746 | large_body_string.append("\r\n"); |
| 2747 | |
| 2748 | MockRead data_reads1[] = { |
| 2749 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2750 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2752 | // 5134 = 12 + 5 * 1024 + 2 |
| 2753 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2754 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2755 | |
| 2756 | // Lastly, the server responds with the actual content. |
| 2757 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2758 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2759 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2760 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | }; |
| 2762 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2763 | // An incorrect reconnect would cause this to be read. |
| 2764 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2765 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2766 | }; |
| 2767 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2768 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2769 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2770 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2771 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2772 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2773 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2775 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2778 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | |
| 2781 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2782 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2785 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2786 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2787 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2788 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2790 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2792 | |
| 2793 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2794 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2797 | ASSERT_TRUE(response); |
| 2798 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2799 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2803 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2804 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2805 | HttpRequestInfo request; |
| 2806 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2807 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2810 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2811 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2812 | MockWrite( |
| 2813 | "GET / HTTP/1.1\r\n" |
| 2814 | "Host: www.example.org\r\n" |
| 2815 | "Connection: keep-alive\r\n\r\n"), |
| 2816 | // This simulates the seemingly successful write to a closed connection |
| 2817 | // if the bug is not fixed. |
| 2818 | MockWrite( |
| 2819 | "GET / HTTP/1.1\r\n" |
| 2820 | "Host: www.example.org\r\n" |
| 2821 | "Connection: keep-alive\r\n" |
| 2822 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2823 | }; |
| 2824 | |
| 2825 | MockRead data_reads1[] = { |
| 2826 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2827 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2829 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2830 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2831 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2832 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2833 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2834 | }; |
| 2835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2836 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2837 | // be issuing -- the final header line contains the credentials. |
| 2838 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2839 | MockWrite( |
| 2840 | "GET / HTTP/1.1\r\n" |
| 2841 | "Host: www.example.org\r\n" |
| 2842 | "Connection: keep-alive\r\n" |
| 2843 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2844 | }; |
| 2845 | |
| 2846 | // Lastly, the server responds with the actual content. |
| 2847 | MockRead data_reads2[] = { |
| 2848 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2849 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2850 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2851 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2852 | }; |
| 2853 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2854 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2855 | data_writes1, arraysize(data_writes1)); |
| 2856 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2857 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2858 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2859 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2861 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2862 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2863 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2864 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2866 | |
| 2867 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2868 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2871 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2872 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2874 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2876 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2878 | |
| 2879 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2880 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2882 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2883 | ASSERT_TRUE(response); |
| 2884 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2885 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2886 | } |
| 2887 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2888 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2889 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2890 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2891 | HttpRequestInfo request; |
| 2892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2893 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2894 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2895 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2896 | |
| 2897 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2898 | session_deps_.proxy_service = |
| 2899 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2900 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2901 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2903 | |
| 2904 | // Since we have proxy, should try to establish tunnel. |
| 2905 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2906 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2907 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2908 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2909 | }; |
| 2910 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2911 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2912 | // connection. |
| 2913 | MockRead data_reads1[] = { |
| 2914 | // No credentials. |
| 2915 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2916 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2917 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2918 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2919 | // Since the first connection couldn't be reused, need to establish another |
| 2920 | // once given credentials. |
| 2921 | MockWrite data_writes2[] = { |
| 2922 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2923 | // be issuing -- the final header line contains the credentials. |
| 2924 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2925 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2926 | "Proxy-Connection: keep-alive\r\n" |
| 2927 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2928 | |
| 2929 | MockWrite("GET / HTTP/1.1\r\n" |
| 2930 | "Host: www.example.org\r\n" |
| 2931 | "Connection: keep-alive\r\n\r\n"), |
| 2932 | }; |
| 2933 | |
| 2934 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2935 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2936 | |
| 2937 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2938 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2939 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2940 | MockRead(SYNCHRONOUS, "hello"), |
| 2941 | }; |
| 2942 | |
| 2943 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2944 | data_writes1, arraysize(data_writes1)); |
| 2945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2946 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2947 | data_writes2, arraysize(data_writes2)); |
| 2948 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2949 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2950 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2951 | |
| 2952 | TestCompletionCallback callback1; |
| 2953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2954 | std::unique_ptr<HttpNetworkTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2955 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2956 | |
| 2957 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2959 | |
| 2960 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2961 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2962 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2963 | log.GetEntries(&entries); |
| 2964 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2965 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2966 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2967 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2968 | entries, pos, |
| 2969 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2970 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2971 | |
| 2972 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2973 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2974 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2975 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2976 | EXPECT_EQ(407, response->headers->response_code()); |
| 2977 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2978 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2979 | |
| 2980 | LoadTimingInfo load_timing_info; |
| 2981 | // CONNECT requests and responses are handled at the connect job level, so |
| 2982 | // the transaction does not yet have a connection. |
| 2983 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2984 | |
| 2985 | TestCompletionCallback callback2; |
| 2986 | |
| 2987 | rv = |
| 2988 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2990 | |
| 2991 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2992 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2993 | |
| 2994 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2995 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2996 | |
| 2997 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2998 | EXPECT_EQ(200, response->headers->response_code()); |
| 2999 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3000 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3001 | |
| 3002 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3003 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3004 | |
| 3005 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3006 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3007 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3008 | |
| 3009 | trans.reset(); |
| 3010 | session->CloseAllConnections(); |
| 3011 | } |
| 3012 | |
| 3013 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3014 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3015 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3016 | HttpRequestInfo request; |
| 3017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3018 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3019 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3020 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3021 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3022 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3023 | session_deps_.proxy_service = |
| 3024 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3025 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3026 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3028 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3029 | // Since we have proxy, should try to establish tunnel. |
| 3030 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3031 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3032 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3033 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3034 | }; |
| 3035 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3036 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3037 | // connection. |
| 3038 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3039 | // No credentials. |
| 3040 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3041 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3042 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3043 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3044 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3045 | MockWrite data_writes2[] = { |
| 3046 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3047 | // be issuing -- the final header line contains the credentials. |
| 3048 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3049 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3050 | "Proxy-Connection: keep-alive\r\n" |
| 3051 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3052 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3053 | MockWrite("GET / HTTP/1.1\r\n" |
| 3054 | "Host: www.example.org\r\n" |
| 3055 | "Connection: keep-alive\r\n\r\n"), |
| 3056 | }; |
| 3057 | |
| 3058 | MockRead data_reads2[] = { |
| 3059 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3060 | |
| 3061 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3062 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3063 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3064 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3065 | }; |
| 3066 | |
| 3067 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3068 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3069 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3070 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3071 | data_writes2, arraysize(data_writes2)); |
| 3072 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3073 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3076 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3078 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3081 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3083 | |
| 3084 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3085 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3086 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3087 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3088 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3089 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3090 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3091 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3092 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3093 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3094 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3095 | |
| 3096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3097 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3099 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3100 | EXPECT_EQ(407, response->headers->response_code()); |
| 3101 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3102 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3103 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3104 | LoadTimingInfo load_timing_info; |
| 3105 | // CONNECT requests and responses are handled at the connect job level, so |
| 3106 | // the transaction does not yet have a connection. |
| 3107 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3109 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3111 | rv = trans->RestartWithAuth( |
| 3112 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3114 | |
| 3115 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3117 | |
| 3118 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3119 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3120 | |
| 3121 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3122 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3123 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3124 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3125 | |
| 3126 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3127 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3128 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3129 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3130 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3131 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3132 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3133 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3134 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3135 | } |
| 3136 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3137 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3138 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3139 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3140 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3141 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3142 | // reused. See http://crbug.com/544255. |
| 3143 | for (int i = 0; i < 2; ++i) { |
| 3144 | HttpRequestInfo request; |
| 3145 | request.method = "GET"; |
| 3146 | request.url = GURL("https://www.example.org/"); |
| 3147 | // Ensure that proxy authentication is attempted even |
| 3148 | // when the no authentication data flag is set. |
| 3149 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3150 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3151 | // Configure against proxy server "myproxy:70". |
| 3152 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3153 | BoundTestNetLog log; |
| 3154 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3158 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3159 | // Since we have proxy, should try to establish tunnel. |
| 3160 | MockWrite data_writes1[] = { |
| 3161 | MockWrite(ASYNC, 0, |
| 3162 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3163 | "Host: www.example.org:443\r\n" |
| 3164 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3166 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3167 | // be issuing -- the final header line contains the credentials. |
| 3168 | MockWrite(ASYNC, 3, |
| 3169 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3170 | "Host: www.example.org:443\r\n" |
| 3171 | "Proxy-Connection: keep-alive\r\n" |
| 3172 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3173 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3174 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3175 | // The proxy responds to the connect with a 407, using a persistent |
| 3176 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3177 | MockRead data_reads1[] = { |
| 3178 | // No credentials. |
| 3179 | MockRead(ASYNC, 1, |
| 3180 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3181 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3182 | "Proxy-Connection: keep-alive\r\n" |
| 3183 | "Content-Length: 10\r\n\r\n"), |
| 3184 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3185 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3186 | // Wrong credentials (wrong password). |
| 3187 | MockRead(ASYNC, 4, |
| 3188 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3189 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3190 | "Proxy-Connection: keep-alive\r\n" |
| 3191 | "Content-Length: 10\r\n\r\n"), |
| 3192 | // No response body because the test stops reading here. |
| 3193 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3194 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3195 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3196 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3197 | arraysize(data_writes1)); |
| 3198 | data1.set_busy_before_sync_reads(true); |
| 3199 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3200 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3201 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3203 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3204 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3205 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3206 | TestNetLogEntry::List entries; |
| 3207 | log.GetEntries(&entries); |
| 3208 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3209 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3210 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3211 | ExpectLogContainsSomewhere( |
| 3212 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3213 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3214 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3215 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3216 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3217 | ASSERT_TRUE(response); |
| 3218 | ASSERT_TRUE(response->headers); |
| 3219 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3220 | EXPECT_EQ(407, response->headers->response_code()); |
| 3221 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3222 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3223 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3224 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3225 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3226 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3227 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3228 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3229 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3230 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3232 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3233 | ASSERT_TRUE(response); |
| 3234 | ASSERT_TRUE(response->headers); |
| 3235 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3236 | EXPECT_EQ(407, response->headers->response_code()); |
| 3237 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3238 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3239 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3240 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3241 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3242 | // out of scope. |
| 3243 | session->CloseAllConnections(); |
| 3244 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3248 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3249 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3250 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3251 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3252 | // reused. See http://crbug.com/544255. |
| 3253 | for (int i = 0; i < 2; ++i) { |
| 3254 | HttpRequestInfo request; |
| 3255 | request.method = "GET"; |
| 3256 | request.url = GURL("https://www.example.org/"); |
| 3257 | // Ensure that proxy authentication is attempted even |
| 3258 | // when the no authentication data flag is set. |
| 3259 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3260 | |
| 3261 | // Configure against proxy server "myproxy:70". |
| 3262 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3263 | BoundTestNetLog log; |
| 3264 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3266 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3267 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3268 | |
| 3269 | // Since we have proxy, should try to establish tunnel. |
| 3270 | MockWrite data_writes1[] = { |
| 3271 | MockWrite(ASYNC, 0, |
| 3272 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3273 | "Host: www.example.org:443\r\n" |
| 3274 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3276 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3277 | // be issuing -- the final header line contains the credentials. |
| 3278 | MockWrite(ASYNC, 3, |
| 3279 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3280 | "Host: www.example.org:443\r\n" |
| 3281 | "Proxy-Connection: keep-alive\r\n" |
| 3282 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3283 | }; |
| 3284 | |
| 3285 | // The proxy responds to the connect with a 407, using a persistent |
| 3286 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3287 | MockRead data_reads1[] = { |
| 3288 | // No credentials. |
| 3289 | MockRead(ASYNC, 1, |
| 3290 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3291 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3292 | "Content-Length: 10\r\n\r\n"), |
| 3293 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3294 | |
| 3295 | // Wrong credentials (wrong password). |
| 3296 | MockRead(ASYNC, 4, |
| 3297 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3298 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3299 | "Content-Length: 10\r\n\r\n"), |
| 3300 | // No response body because the test stops reading here. |
| 3301 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3302 | }; |
| 3303 | |
| 3304 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3305 | arraysize(data_writes1)); |
| 3306 | data1.set_busy_before_sync_reads(true); |
| 3307 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3308 | |
| 3309 | TestCompletionCallback callback1; |
| 3310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3311 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3312 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3313 | |
| 3314 | TestNetLogEntry::List entries; |
| 3315 | log.GetEntries(&entries); |
| 3316 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3317 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3318 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3319 | ExpectLogContainsSomewhere( |
| 3320 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3321 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3322 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3323 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3324 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3325 | ASSERT_TRUE(response); |
| 3326 | ASSERT_TRUE(response->headers); |
| 3327 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3328 | EXPECT_EQ(407, response->headers->response_code()); |
| 3329 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3330 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3331 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3332 | |
| 3333 | TestCompletionCallback callback2; |
| 3334 | |
| 3335 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3336 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3337 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3338 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3340 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3341 | ASSERT_TRUE(response); |
| 3342 | ASSERT_TRUE(response->headers); |
| 3343 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3344 | EXPECT_EQ(407, response->headers->response_code()); |
| 3345 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3346 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3347 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3348 | |
| 3349 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3350 | // out of scope. |
| 3351 | session->CloseAllConnections(); |
| 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3356 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3357 | // the case the server sends extra data on the original socket, so it can't be |
| 3358 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3359 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3360 | HttpRequestInfo request; |
| 3361 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3362 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3363 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3364 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3365 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3366 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3367 | session_deps_.proxy_service = |
| 3368 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3369 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3370 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3372 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3373 | // Since we have proxy, should try to establish tunnel. |
| 3374 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3375 | MockWrite(ASYNC, 0, |
| 3376 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3377 | "Host: www.example.org:443\r\n" |
| 3378 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3379 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3380 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3381 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3382 | // extra data, so the socket cannot be reused. |
| 3383 | MockRead data_reads1[] = { |
| 3384 | // No credentials. |
| 3385 | MockRead(ASYNC, 1, |
| 3386 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3387 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3388 | "Content-Length: 10\r\n\r\n"), |
| 3389 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3390 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3391 | }; |
| 3392 | |
| 3393 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3394 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3395 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3396 | MockWrite(ASYNC, 0, |
| 3397 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3398 | "Host: www.example.org:443\r\n" |
| 3399 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3401 | |
| 3402 | MockWrite(ASYNC, 2, |
| 3403 | "GET / HTTP/1.1\r\n" |
| 3404 | "Host: www.example.org\r\n" |
| 3405 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3406 | }; |
| 3407 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3408 | MockRead data_reads2[] = { |
| 3409 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3410 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3411 | MockRead(ASYNC, 3, |
| 3412 | "HTTP/1.1 200 OK\r\n" |
| 3413 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3414 | "Content-Length: 5\r\n\r\n"), |
| 3415 | // No response body because the test stops reading here. |
| 3416 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3417 | }; |
| 3418 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3419 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3420 | arraysize(data_writes1)); |
| 3421 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3422 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3423 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3424 | arraysize(data_writes2)); |
| 3425 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3426 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3429 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3431 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3432 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3433 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3434 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3435 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3436 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3437 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3438 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3439 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3440 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3441 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3442 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3443 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3444 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3445 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3446 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3448 | ASSERT_TRUE(response); |
| 3449 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3450 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3451 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3452 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3453 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3454 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3455 | LoadTimingInfo load_timing_info; |
| 3456 | // CONNECT requests and responses are handled at the connect job level, so |
| 3457 | // the transaction does not yet have a connection. |
| 3458 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3460 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3461 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3462 | rv = |
| 3463 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3464 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3465 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3466 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3467 | EXPECT_EQ(200, response->headers->response_code()); |
| 3468 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3469 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3470 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | // The password prompt info should not be set. |
| 3472 | EXPECT_FALSE(response->auth_challenge); |
| 3473 | |
| 3474 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3475 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3476 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3477 | |
| 3478 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3479 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3480 | } |
| 3481 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3482 | // Test the case a proxy closes a socket while the challenge body is being |
| 3483 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3484 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3485 | HttpRequestInfo request; |
| 3486 | request.method = "GET"; |
| 3487 | request.url = GURL("https://www.example.org/"); |
| 3488 | // Ensure that proxy authentication is attempted even |
| 3489 | // when the no authentication data flag is set. |
| 3490 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3491 | |
| 3492 | // Configure against proxy server "myproxy:70". |
| 3493 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3494 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3497 | |
| 3498 | // Since we have proxy, should try to establish tunnel. |
| 3499 | MockWrite data_writes1[] = { |
| 3500 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3501 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3502 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3503 | }; |
| 3504 | |
| 3505 | // The proxy responds to the connect with a 407, using a persistent |
| 3506 | // connection. |
| 3507 | MockRead data_reads1[] = { |
| 3508 | // No credentials. |
| 3509 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3510 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3511 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3512 | // Server hands up in the middle of the body. |
| 3513 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3514 | }; |
| 3515 | |
| 3516 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3517 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3518 | // be issuing -- the final header line contains the credentials. |
| 3519 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3520 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3521 | "Proxy-Connection: keep-alive\r\n" |
| 3522 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3523 | |
| 3524 | MockWrite("GET / HTTP/1.1\r\n" |
| 3525 | "Host: www.example.org\r\n" |
| 3526 | "Connection: keep-alive\r\n\r\n"), |
| 3527 | }; |
| 3528 | |
| 3529 | MockRead data_reads2[] = { |
| 3530 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3531 | |
| 3532 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3533 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3534 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3535 | MockRead(SYNCHRONOUS, "hello"), |
| 3536 | }; |
| 3537 | |
| 3538 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3539 | data_writes1, arraysize(data_writes1)); |
| 3540 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3541 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3542 | data_writes2, arraysize(data_writes2)); |
| 3543 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3544 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3546 | |
| 3547 | TestCompletionCallback callback; |
| 3548 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3549 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3550 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3552 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3553 | ASSERT_TRUE(response); |
| 3554 | ASSERT_TRUE(response->headers); |
| 3555 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3556 | EXPECT_EQ(407, response->headers->response_code()); |
| 3557 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3559 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3560 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3562 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3563 | ASSERT_TRUE(response); |
| 3564 | ASSERT_TRUE(response->headers); |
| 3565 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3566 | EXPECT_EQ(200, response->headers->response_code()); |
| 3567 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3568 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3569 | EXPECT_EQ("hello", body); |
| 3570 | } |
| 3571 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3572 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3573 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3574 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3575 | HttpRequestInfo request; |
| 3576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3577 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3578 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3579 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3580 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3583 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3585 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3586 | // Since we have proxy, should try to establish tunnel. |
| 3587 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3588 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3589 | "Host: www.example.org:443\r\n" |
| 3590 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3591 | }; |
| 3592 | |
| 3593 | // The proxy responds to the connect with a 407. |
| 3594 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3595 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3596 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3597 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3599 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3600 | }; |
| 3601 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3602 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3603 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3606 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3607 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3608 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3610 | |
| 3611 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3612 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3613 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3614 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3615 | ASSERT_TRUE(response); |
| 3616 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3617 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3618 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3619 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3620 | |
| 3621 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3622 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3623 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3624 | |
| 3625 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3626 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3627 | } |
| 3628 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3629 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3630 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3631 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3632 | HttpRequestInfo request; |
| 3633 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3634 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3635 | |
| 3636 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3637 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3638 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3642 | |
| 3643 | // Since we have proxy, should try to establish tunnel. |
| 3644 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3645 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3646 | "Host: www.example.org:443\r\n" |
| 3647 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3648 | }; |
| 3649 | |
| 3650 | // The proxy responds to the connect with a 407. |
| 3651 | MockRead data_reads[] = { |
| 3652 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3653 | MockRead("X-Foo: bar\r\n"), |
| 3654 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3655 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3656 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3658 | }; |
| 3659 | |
| 3660 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3661 | arraysize(data_writes)); |
| 3662 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3663 | |
| 3664 | TestCompletionCallback callback; |
| 3665 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3666 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3668 | |
| 3669 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3670 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3672 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3673 | ASSERT_TRUE(response); |
| 3674 | ASSERT_TRUE(response->headers); |
| 3675 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3676 | EXPECT_EQ(407, response->headers->response_code()); |
| 3677 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3678 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3679 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3680 | |
| 3681 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3682 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3683 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3684 | |
| 3685 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3686 | session->CloseAllConnections(); |
| 3687 | } |
| 3688 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3689 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3690 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3691 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3692 | HttpRequestInfo request; |
| 3693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3695 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3696 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3699 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3700 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3701 | MockWrite( |
| 3702 | "GET / HTTP/1.1\r\n" |
| 3703 | "Host: www.example.org\r\n" |
| 3704 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3705 | }; |
| 3706 | |
| 3707 | MockRead data_reads1[] = { |
| 3708 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3709 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3710 | // Large content-length -- won't matter, as connection will be reset. |
| 3711 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3712 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3713 | }; |
| 3714 | |
| 3715 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3716 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3717 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3719 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3720 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3721 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3723 | |
| 3724 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3725 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3726 | } |
| 3727 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3728 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3729 | // through a non-authenticating proxy. The request should fail with |
| 3730 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3731 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3732 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3733 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3734 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3735 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3736 | HttpRequestInfo request; |
| 3737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3738 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3739 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3740 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3741 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3742 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3744 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3745 | // Since we have proxy, should try to establish tunnel. |
| 3746 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3747 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3748 | "Host: www.example.org:443\r\n" |
| 3749 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3750 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3751 | MockWrite("GET / HTTP/1.1\r\n" |
| 3752 | "Host: www.example.org\r\n" |
| 3753 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3754 | }; |
| 3755 | |
| 3756 | MockRead data_reads1[] = { |
| 3757 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3758 | |
| 3759 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3760 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3761 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3762 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3763 | }; |
| 3764 | |
| 3765 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3766 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3768 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3771 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3774 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3775 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3777 | |
| 3778 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3779 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3780 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3781 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3782 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3783 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3784 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3785 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3786 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3787 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3788 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3789 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3790 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3791 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3792 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3793 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3794 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3795 | HttpRequestInfo request; |
| 3796 | request.method = "GET"; |
| 3797 | request.url = GURL("https://www.example.org/"); |
| 3798 | |
| 3799 | // Configure against proxy server "myproxy:70". |
| 3800 | session_deps_.proxy_service = |
| 3801 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3803 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3804 | new HttpAuthHandlerMock::Factory()); |
| 3805 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3806 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3807 | mock_handler->set_allows_default_credentials(true); |
| 3808 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3809 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3810 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3811 | |
| 3812 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3813 | NetLog net_log; |
| 3814 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3815 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3816 | |
| 3817 | // Since we have proxy, should try to establish tunnel. |
| 3818 | MockWrite data_writes1[] = { |
| 3819 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3820 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3821 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3822 | }; |
| 3823 | |
| 3824 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3825 | // connection. |
| 3826 | MockRead data_reads1[] = { |
| 3827 | // No credentials. |
| 3828 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3829 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3830 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3831 | }; |
| 3832 | |
| 3833 | // Since the first connection couldn't be reused, need to establish another |
| 3834 | // once given credentials. |
| 3835 | MockWrite data_writes2[] = { |
| 3836 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3837 | // be issuing -- the final header line contains the credentials. |
| 3838 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3839 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3840 | "Proxy-Connection: keep-alive\r\n" |
| 3841 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3842 | |
| 3843 | MockWrite("GET / HTTP/1.1\r\n" |
| 3844 | "Host: www.example.org\r\n" |
| 3845 | "Connection: keep-alive\r\n\r\n"), |
| 3846 | }; |
| 3847 | |
| 3848 | MockRead data_reads2[] = { |
| 3849 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3850 | |
| 3851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3852 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3853 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3854 | MockRead(SYNCHRONOUS, "hello"), |
| 3855 | }; |
| 3856 | |
| 3857 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3858 | data_writes1, arraysize(data_writes1)); |
| 3859 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3860 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3861 | data_writes2, arraysize(data_writes2)); |
| 3862 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3863 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3864 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3866 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3867 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3868 | |
| 3869 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3870 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3871 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3872 | |
| 3873 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3874 | ASSERT_TRUE(response); |
| 3875 | ASSERT_TRUE(response->headers); |
| 3876 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3877 | EXPECT_EQ(407, response->headers->response_code()); |
| 3878 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3879 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3880 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3881 | |
| 3882 | LoadTimingInfo load_timing_info; |
| 3883 | // CONNECT requests and responses are handled at the connect job level, so |
| 3884 | // the transaction does not yet have a connection. |
| 3885 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3886 | |
| 3887 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3888 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3889 | response = trans->GetResponseInfo(); |
| 3890 | ASSERT_TRUE(response); |
| 3891 | ASSERT_TRUE(response->headers); |
| 3892 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3893 | EXPECT_EQ(200, response->headers->response_code()); |
| 3894 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3895 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3896 | |
| 3897 | // The password prompt info should not be set. |
| 3898 | EXPECT_FALSE(response->auth_challenge); |
| 3899 | |
| 3900 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3901 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3902 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3903 | |
| 3904 | trans.reset(); |
| 3905 | session->CloseAllConnections(); |
| 3906 | } |
| 3907 | |
| 3908 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3909 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3910 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3911 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3912 | HttpRequestInfo request; |
| 3913 | request.method = "GET"; |
| 3914 | request.url = GURL("https://www.example.org/"); |
| 3915 | |
| 3916 | // Configure against proxy server "myproxy:70". |
| 3917 | session_deps_.proxy_service = |
| 3918 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3920 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3921 | new HttpAuthHandlerMock::Factory()); |
| 3922 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3923 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3924 | mock_handler->set_allows_default_credentials(true); |
| 3925 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3926 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3927 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3928 | |
| 3929 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3930 | NetLog net_log; |
| 3931 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3932 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3933 | |
| 3934 | // Should try to establish tunnel. |
| 3935 | MockWrite data_writes1[] = { |
| 3936 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3937 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3938 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3939 | |
| 3940 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3941 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3942 | "Proxy-Connection: keep-alive\r\n" |
| 3943 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3944 | }; |
| 3945 | |
| 3946 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3947 | // connection. |
| 3948 | MockRead data_reads1[] = { |
| 3949 | // No credentials. |
| 3950 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3951 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3952 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3953 | }; |
| 3954 | |
| 3955 | // Since the first connection was closed, need to establish another once given |
| 3956 | // credentials. |
| 3957 | MockWrite data_writes2[] = { |
| 3958 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3959 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3960 | "Proxy-Connection: keep-alive\r\n" |
| 3961 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3962 | |
| 3963 | MockWrite("GET / HTTP/1.1\r\n" |
| 3964 | "Host: www.example.org\r\n" |
| 3965 | "Connection: keep-alive\r\n\r\n"), |
| 3966 | }; |
| 3967 | |
| 3968 | MockRead data_reads2[] = { |
| 3969 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3970 | |
| 3971 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3972 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3973 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3974 | MockRead(SYNCHRONOUS, "hello"), |
| 3975 | }; |
| 3976 | |
| 3977 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3978 | data_writes1, arraysize(data_writes1)); |
| 3979 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3980 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3981 | data_writes2, arraysize(data_writes2)); |
| 3982 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3983 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3986 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3987 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3988 | |
| 3989 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3990 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3991 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3992 | |
| 3993 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3994 | ASSERT_TRUE(response); |
| 3995 | ASSERT_TRUE(response->headers); |
| 3996 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3997 | EXPECT_EQ(407, response->headers->response_code()); |
| 3998 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3999 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4000 | EXPECT_FALSE(response->auth_challenge); |
| 4001 | |
| 4002 | LoadTimingInfo load_timing_info; |
| 4003 | // CONNECT requests and responses are handled at the connect job level, so |
| 4004 | // the transaction does not yet have a connection. |
| 4005 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4006 | |
| 4007 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4008 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4009 | |
| 4010 | response = trans->GetResponseInfo(); |
| 4011 | ASSERT_TRUE(response); |
| 4012 | ASSERT_TRUE(response->headers); |
| 4013 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4014 | EXPECT_EQ(200, response->headers->response_code()); |
| 4015 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4016 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4017 | |
| 4018 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4019 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4020 | |
| 4021 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4022 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4023 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4024 | |
| 4025 | trans.reset(); |
| 4026 | session->CloseAllConnections(); |
| 4027 | } |
| 4028 | |
| 4029 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4030 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4031 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4032 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4033 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4034 | HttpRequestInfo request; |
| 4035 | request.method = "GET"; |
| 4036 | request.url = GURL("https://www.example.org/"); |
| 4037 | |
| 4038 | // Configure against proxy server "myproxy:70". |
| 4039 | session_deps_.proxy_service = |
| 4040 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4041 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4042 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4043 | new HttpAuthHandlerMock::Factory()); |
| 4044 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4045 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4046 | mock_handler->set_allows_default_credentials(true); |
| 4047 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4048 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4049 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4050 | |
| 4051 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4052 | NetLog net_log; |
| 4053 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4054 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4055 | |
| 4056 | // Should try to establish tunnel. |
| 4057 | MockWrite data_writes1[] = { |
| 4058 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4059 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4060 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4061 | |
| 4062 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4063 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | "Proxy-Connection: keep-alive\r\n" |
| 4065 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4066 | }; |
| 4067 | |
| 4068 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4069 | // second request is sent. |
| 4070 | MockRead data_reads1[] = { |
| 4071 | // No credentials. |
| 4072 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4073 | MockRead("Content-Length: 0\r\n"), |
| 4074 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4075 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4076 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4077 | }; |
| 4078 | |
| 4079 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4080 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4081 | // request. |
| 4082 | MockWrite data_writes2[] = { |
| 4083 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4084 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4085 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4086 | }; |
| 4087 | |
| 4088 | // The proxy, having had more than enough of us, just hangs up. |
| 4089 | MockRead data_reads2[] = { |
| 4090 | // No credentials. |
| 4091 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4092 | }; |
| 4093 | |
| 4094 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4095 | data_writes1, arraysize(data_writes1)); |
| 4096 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4097 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4098 | data_writes2, arraysize(data_writes2)); |
| 4099 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4101 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4102 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4103 | |
| 4104 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4105 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4106 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4107 | |
| 4108 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4109 | ASSERT_TRUE(response); |
| 4110 | ASSERT_TRUE(response->headers); |
| 4111 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4112 | EXPECT_EQ(407, response->headers->response_code()); |
| 4113 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4114 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4115 | EXPECT_FALSE(response->auth_challenge); |
| 4116 | |
| 4117 | LoadTimingInfo load_timing_info; |
| 4118 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4119 | |
| 4120 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4121 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4122 | |
| 4123 | trans.reset(); |
| 4124 | session->CloseAllConnections(); |
| 4125 | } |
| 4126 | |
| 4127 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4128 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4129 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4130 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4131 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4132 | HttpRequestInfo request; |
| 4133 | request.method = "GET"; |
| 4134 | request.url = GURL("https://www.example.org/"); |
| 4135 | |
| 4136 | // Configure against proxy server "myproxy:70". |
| 4137 | session_deps_.proxy_service = |
| 4138 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4139 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4140 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4141 | new HttpAuthHandlerMock::Factory()); |
| 4142 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4143 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4144 | mock_handler->set_allows_default_credentials(true); |
| 4145 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4146 | HttpAuth::AUTH_PROXY); |
| 4147 | // Add another handler for the second challenge. It supports default |
| 4148 | // credentials, but they shouldn't be used, since they were already tried. |
| 4149 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4150 | mock_handler->set_allows_default_credentials(true); |
| 4151 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4152 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4153 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4154 | |
| 4155 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4156 | NetLog net_log; |
| 4157 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4158 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4159 | |
| 4160 | // Should try to establish tunnel. |
| 4161 | MockWrite data_writes1[] = { |
| 4162 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4163 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4164 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4165 | }; |
| 4166 | |
| 4167 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4168 | // connection. |
| 4169 | MockRead data_reads1[] = { |
| 4170 | // No credentials. |
| 4171 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4172 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4173 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4174 | }; |
| 4175 | |
| 4176 | // Since the first connection was closed, need to establish another once given |
| 4177 | // credentials. |
| 4178 | MockWrite data_writes2[] = { |
| 4179 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4180 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4181 | "Proxy-Connection: keep-alive\r\n" |
| 4182 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4183 | }; |
| 4184 | |
| 4185 | MockRead data_reads2[] = { |
| 4186 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4187 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4188 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4189 | }; |
| 4190 | |
| 4191 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4192 | data_writes1, arraysize(data_writes1)); |
| 4193 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4194 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4195 | data_writes2, arraysize(data_writes2)); |
| 4196 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4197 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4200 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4201 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4202 | |
| 4203 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4204 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4205 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4206 | |
| 4207 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4208 | ASSERT_TRUE(response); |
| 4209 | ASSERT_TRUE(response->headers); |
| 4210 | EXPECT_EQ(407, response->headers->response_code()); |
| 4211 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4212 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4213 | EXPECT_FALSE(response->auth_challenge); |
| 4214 | |
| 4215 | LoadTimingInfo load_timing_info; |
| 4216 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4217 | |
| 4218 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4219 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4220 | response = trans->GetResponseInfo(); |
| 4221 | ASSERT_TRUE(response); |
| 4222 | ASSERT_TRUE(response->headers); |
| 4223 | EXPECT_EQ(407, response->headers->response_code()); |
| 4224 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4225 | EXPECT_TRUE(response->auth_challenge); |
| 4226 | |
| 4227 | trans.reset(); |
| 4228 | session->CloseAllConnections(); |
| 4229 | } |
| 4230 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4231 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4232 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4233 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4234 | // authentication handshake can continue with the same scheme but with a |
| 4235 | // different identity. |
| 4236 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4237 | HttpRequestInfo request; |
| 4238 | request.method = "GET"; |
| 4239 | request.url = GURL("http://www.example.org/"); |
| 4240 | |
| 4241 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 4242 | new HttpAuthHandlerMock::Factory()); |
| 4243 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4244 | |
| 4245 | // First handler. Uses default credentials, but barfs at generate auth token. |
| 4246 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 4247 | mock_handler->set_allows_default_credentials(true); |
| 4248 | mock_handler->set_allows_explicit_credentials(true); |
| 4249 | mock_handler->set_connection_based(true); |
| 4250 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4251 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4252 | HttpAuth::AUTH_SERVER); |
| 4253 | |
| 4254 | // Add another handler for the second challenge. It supports default |
| 4255 | // credentials, but they shouldn't be used, since they were already tried. |
| 4256 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4257 | mock_handler->set_allows_default_credentials(true); |
| 4258 | mock_handler->set_allows_explicit_credentials(true); |
| 4259 | mock_handler->set_connection_based(true); |
| 4260 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4261 | HttpAuth::AUTH_SERVER); |
| 4262 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4263 | |
| 4264 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4265 | |
| 4266 | MockWrite data_writes1[] = { |
| 4267 | MockWrite("GET / HTTP/1.1\r\n" |
| 4268 | "Host: www.example.org\r\n" |
| 4269 | "Connection: keep-alive\r\n\r\n"), |
| 4270 | }; |
| 4271 | |
| 4272 | MockRead data_reads1[] = { |
| 4273 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4274 | "WWW-Authenticate: Mock\r\n" |
| 4275 | "Connection: keep-alive\r\n\r\n"), |
| 4276 | }; |
| 4277 | |
| 4278 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4279 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4280 | // transaction procceds without an authorization header. |
| 4281 | MockWrite data_writes2[] = { |
| 4282 | MockWrite("GET / HTTP/1.1\r\n" |
| 4283 | "Host: www.example.org\r\n" |
| 4284 | "Connection: keep-alive\r\n\r\n"), |
| 4285 | }; |
| 4286 | |
| 4287 | MockRead data_reads2[] = { |
| 4288 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4289 | "WWW-Authenticate: Mock\r\n" |
| 4290 | "Connection: keep-alive\r\n\r\n"), |
| 4291 | }; |
| 4292 | |
| 4293 | MockWrite data_writes3[] = { |
| 4294 | MockWrite("GET / HTTP/1.1\r\n" |
| 4295 | "Host: www.example.org\r\n" |
| 4296 | "Connection: keep-alive\r\n" |
| 4297 | "Authorization: auth_token\r\n\r\n"), |
| 4298 | }; |
| 4299 | |
| 4300 | MockRead data_reads3[] = { |
| 4301 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4302 | "Content-Length: 5\r\n" |
| 4303 | "Content-Type: text/plain\r\n" |
| 4304 | "Connection: keep-alive\r\n\r\n" |
| 4305 | "Hello"), |
| 4306 | }; |
| 4307 | |
| 4308 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4309 | data_writes1, arraysize(data_writes1)); |
| 4310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4311 | |
| 4312 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4313 | data_writes2, arraysize(data_writes2)); |
| 4314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4315 | |
| 4316 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4317 | data_writes3, arraysize(data_writes3)); |
| 4318 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4319 | |
| 4320 | std::unique_ptr<HttpNetworkTransaction> trans( |
| 4321 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4322 | |
| 4323 | TestCompletionCallback callback; |
| 4324 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4325 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4326 | |
| 4327 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4328 | ASSERT_TRUE(response); |
| 4329 | ASSERT_TRUE(response->headers); |
| 4330 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4331 | |
| 4332 | // The following three tests assert that an authentication challenge was |
| 4333 | // received and that the stack is ready to respond to the challenge using |
| 4334 | // ambient credentials. |
| 4335 | EXPECT_EQ(401, response->headers->response_code()); |
| 4336 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4337 | EXPECT_FALSE(response->auth_challenge); |
| 4338 | |
| 4339 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4340 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4341 | response = trans->GetResponseInfo(); |
| 4342 | ASSERT_TRUE(response); |
| 4343 | ASSERT_TRUE(response->headers); |
| 4344 | |
| 4345 | // The following three tests assert that an authentication challenge was |
| 4346 | // received and that the stack needs explicit credentials before it is ready |
| 4347 | // to respond to the challenge. |
| 4348 | EXPECT_EQ(401, response->headers->response_code()); |
| 4349 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4350 | EXPECT_TRUE(response->auth_challenge); |
| 4351 | |
| 4352 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4353 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4354 | response = trans->GetResponseInfo(); |
| 4355 | ASSERT_TRUE(response); |
| 4356 | ASSERT_TRUE(response->headers); |
| 4357 | EXPECT_EQ(200, response->headers->response_code()); |
| 4358 | |
| 4359 | trans.reset(); |
| 4360 | session->CloseAllConnections(); |
| 4361 | } |
| 4362 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4363 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4364 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4365 | HttpRequestInfo request1; |
| 4366 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4367 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4368 | |
| 4369 | HttpRequestInfo request2; |
| 4370 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4371 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4372 | |
| 4373 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4374 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4375 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4376 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4378 | |
| 4379 | // Since we have proxy, should try to establish tunnel. |
| 4380 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4381 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4382 | "Host: www.example.org:443\r\n" |
| 4383 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4384 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4385 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4386 | "Host: www.example.org\r\n" |
| 4387 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4388 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4389 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4390 | "Host: www.example.org\r\n" |
| 4391 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4392 | }; |
| 4393 | |
| 4394 | // The proxy responds to the connect with a 407, using a persistent |
| 4395 | // connection. |
| 4396 | MockRead data_reads1[] = { |
| 4397 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4398 | |
| 4399 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4400 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4401 | MockRead(SYNCHRONOUS, "1"), |
| 4402 | |
| 4403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4404 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4405 | MockRead(SYNCHRONOUS, "22"), |
| 4406 | }; |
| 4407 | |
| 4408 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4409 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4411 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4413 | |
| 4414 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4415 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4416 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4417 | |
| 4418 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4420 | |
| 4421 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4423 | |
| 4424 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4425 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4426 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4427 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4428 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4429 | |
| 4430 | LoadTimingInfo load_timing_info1; |
| 4431 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4432 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4433 | |
| 4434 | trans1.reset(); |
| 4435 | |
| 4436 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4437 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4439 | |
| 4440 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4441 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4442 | |
| 4443 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4444 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4445 | |
| 4446 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4447 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4448 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4449 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4450 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4451 | |
| 4452 | LoadTimingInfo load_timing_info2; |
| 4453 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4454 | TestLoadTimingReused(load_timing_info2); |
| 4455 | |
| 4456 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4457 | |
| 4458 | trans2.reset(); |
| 4459 | session->CloseAllConnections(); |
| 4460 | } |
| 4461 | |
| 4462 | // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4463 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4464 | HttpRequestInfo request1; |
| 4465 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4466 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4467 | |
| 4468 | HttpRequestInfo request2; |
| 4469 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4471 | |
| 4472 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4473 | session_deps_.proxy_service = |
| 4474 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4475 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4476 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4478 | |
| 4479 | // Since we have proxy, should try to establish tunnel. |
| 4480 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4481 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4482 | "Host: www.example.org:443\r\n" |
| 4483 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4484 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4485 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4486 | "Host: www.example.org\r\n" |
| 4487 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4488 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4489 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4490 | "Host: www.example.org\r\n" |
| 4491 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4492 | }; |
| 4493 | |
| 4494 | // The proxy responds to the connect with a 407, using a persistent |
| 4495 | // connection. |
| 4496 | MockRead data_reads1[] = { |
| 4497 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4498 | |
| 4499 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4500 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4501 | MockRead(SYNCHRONOUS, "1"), |
| 4502 | |
| 4503 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4504 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4505 | MockRead(SYNCHRONOUS, "22"), |
| 4506 | }; |
| 4507 | |
| 4508 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4509 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4510 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4511 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4512 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4513 | |
| 4514 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4515 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4516 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4517 | |
| 4518 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4520 | |
| 4521 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4523 | |
| 4524 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4525 | ASSERT_TRUE(response1); |
| 4526 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4528 | |
| 4529 | LoadTimingInfo load_timing_info1; |
| 4530 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4531 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4532 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4533 | |
| 4534 | trans1.reset(); |
| 4535 | |
| 4536 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4537 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4538 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4539 | |
| 4540 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4542 | |
| 4543 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4545 | |
| 4546 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4547 | ASSERT_TRUE(response2); |
| 4548 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4549 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4550 | |
| 4551 | LoadTimingInfo load_timing_info2; |
| 4552 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4553 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4554 | |
| 4555 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4556 | |
| 4557 | trans2.reset(); |
| 4558 | session->CloseAllConnections(); |
| 4559 | } |
| 4560 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4561 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4562 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4563 | HttpRequestInfo request; |
| 4564 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4565 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4566 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4567 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4568 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4569 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4570 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4572 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4573 | // Since we have proxy, should use full url |
| 4574 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4575 | MockWrite( |
| 4576 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4577 | "Host: www.example.org\r\n" |
| 4578 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4579 | }; |
| 4580 | |
| 4581 | MockRead data_reads1[] = { |
| 4582 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4583 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4584 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4585 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4586 | }; |
| 4587 | |
| 4588 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4589 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4590 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4591 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4594 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4598 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4600 | |
| 4601 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4603 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4604 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4605 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4606 | TestLoadTimingNotReused(load_timing_info, |
| 4607 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4609 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4610 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4611 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4612 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4613 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4614 | EXPECT_EQ(200, response->headers->response_code()); |
| 4615 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4616 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4617 | |
| 4618 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4619 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4620 | } |
| 4621 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4622 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4623 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4624 | HttpRequestInfo request; |
| 4625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4627 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4628 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4629 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4630 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4631 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4633 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4634 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4635 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4636 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4637 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4638 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4639 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4640 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4641 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4642 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4643 | }; |
| 4644 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4645 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4646 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4647 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4648 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4649 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4650 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4653 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4657 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4659 | |
| 4660 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4661 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4662 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4663 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4664 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4665 | TestLoadTimingNotReused(load_timing_info, |
| 4666 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4669 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4670 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4671 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4672 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4673 | |
| 4674 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4675 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4676 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4677 | } |
| 4678 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4679 | // Verifies that a session which races and wins against the owning transaction |
| 4680 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4681 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4682 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4683 | HttpRequestInfo request; |
| 4684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4685 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4686 | |
| 4687 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4688 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4689 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4690 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4692 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4693 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4694 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4695 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4696 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4697 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4698 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4699 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4700 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4701 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4702 | }; |
| 4703 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4704 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4705 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4706 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4707 | |
| 4708 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4709 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4711 | |
| 4712 | TestCompletionCallback callback1; |
| 4713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4715 | |
| 4716 | // Stall the hostname resolution begun by the transaction. |
| 4717 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4718 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4720 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4722 | |
| 4723 | // Race a session to the proxy, which completes first. |
| 4724 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4725 | SpdySessionKey key( |
| 4726 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4727 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4728 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4729 | |
| 4730 | // Unstall the resolution begun by the transaction. |
| 4731 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4732 | session_deps_.host_resolver->ResolveAllPending(); |
| 4733 | |
| 4734 | EXPECT_FALSE(callback1.have_result()); |
| 4735 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4736 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4738 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4739 | ASSERT_TRUE(response); |
| 4740 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4741 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4742 | |
| 4743 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4744 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4745 | EXPECT_EQ(kUploadData, response_data); |
| 4746 | } |
| 4747 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4748 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4749 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4750 | HttpRequestInfo request; |
| 4751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4752 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4753 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4754 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4755 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4756 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4757 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4759 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4760 | // The first request will be a bare GET, the second request will be a |
| 4761 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4762 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4763 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4764 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4765 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4766 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4767 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4768 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4769 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4770 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4771 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4772 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4773 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4774 | }; |
| 4775 | |
| 4776 | // The first response is a 407 proxy authentication challenge, and the second |
| 4777 | // response will be a 200 response since the second request includes a valid |
| 4778 | // Authorization header. |
| 4779 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4780 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4781 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4782 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4783 | "407 Proxy Authentication Required", kExtraAuthenticationHeaders, |
| 4784 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4785 | SpdySerializedFrame body_authentication( |
| 4786 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4787 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4788 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4789 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4790 | CreateMockRead(resp_authentication, 1), |
| 4791 | CreateMockRead(body_authentication, 2), |
| 4792 | CreateMockRead(resp_data, 4), |
| 4793 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4794 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4795 | }; |
| 4796 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4797 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4798 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4799 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4800 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4801 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4802 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4805 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4807 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4809 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4811 | |
| 4812 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4815 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4816 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4817 | ASSERT_TRUE(response); |
| 4818 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4819 | EXPECT_EQ(407, response->headers->response_code()); |
| 4820 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4821 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4823 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4825 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4827 | |
| 4828 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4831 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4832 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4833 | ASSERT_TRUE(response_restart); |
| 4834 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4835 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4836 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4837 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4838 | } |
| 4839 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4840 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4841 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4842 | HttpRequestInfo request; |
| 4843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4844 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4845 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4846 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4847 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4848 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4849 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4853 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4854 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4855 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4856 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4857 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4858 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4859 | const char get[] = |
| 4860 | "GET / HTTP/1.1\r\n" |
| 4861 | "Host: www.example.org\r\n" |
| 4862 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4863 | SpdySerializedFrame wrapped_get( |
| 4864 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4865 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4866 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4867 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4868 | SpdySerializedFrame wrapped_get_resp( |
| 4869 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4870 | SpdySerializedFrame wrapped_body( |
| 4871 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4872 | SpdySerializedFrame window_update( |
| 4873 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4874 | |
| 4875 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4876 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4877 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4878 | }; |
| 4879 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4880 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4881 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4882 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4883 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4884 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4885 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4886 | }; |
| 4887 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4888 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4889 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4890 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4891 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4892 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4893 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4895 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4898 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4900 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4902 | |
| 4903 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4904 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4905 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4906 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4907 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4908 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4911 | ASSERT_TRUE(response); |
| 4912 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4913 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4914 | |
| 4915 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4916 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4917 | EXPECT_EQ("1234567890", response_data); |
| 4918 | } |
| 4919 | |
| 4920 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4921 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4922 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4923 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4924 | HttpRequestInfo request; |
| 4925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4926 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4927 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4928 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4929 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4930 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4931 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4934 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4935 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4936 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4937 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4938 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4939 | // fetch https://www.example.org/ via SPDY |
| 4940 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4941 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4942 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4943 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4944 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4945 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4946 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4947 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4948 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4950 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4951 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4952 | SpdySerializedFrame window_update_get_resp( |
| 4953 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4954 | SpdySerializedFrame window_update_body( |
| 4955 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4956 | |
| 4957 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4958 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4959 | CreateMockWrite(window_update_get_resp, 6), |
| 4960 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4961 | }; |
| 4962 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4963 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4964 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4965 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4966 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4967 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4968 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4969 | }; |
| 4970 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4971 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4972 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4973 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4975 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4976 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4978 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4979 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4980 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4982 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4983 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4984 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4986 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4987 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4988 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4989 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4990 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4991 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4992 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4993 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4994 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4995 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4996 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4998 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4999 | ASSERT_TRUE(response); |
| 5000 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5001 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5002 | |
| 5003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5004 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5005 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5009 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5010 | HttpRequestInfo request; |
| 5011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5012 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5013 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5014 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5015 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5016 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5017 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5020 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5021 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5022 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5023 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5024 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5025 | SpdySerializedFrame get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5026 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5027 | |
| 5028 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5029 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5030 | }; |
| 5031 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5032 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5033 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5035 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5036 | }; |
| 5037 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5038 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5039 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5040 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5041 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5042 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5043 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5045 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5046 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5049 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5051 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5053 | |
| 5054 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5055 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5056 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5057 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5058 | } |
| 5059 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5060 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5061 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5062 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5063 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5064 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5065 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5066 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5067 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5068 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5069 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5070 | |
| 5071 | HttpRequestInfo request1; |
| 5072 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5073 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5074 | request1.load_flags = 0; |
| 5075 | |
| 5076 | HttpRequestInfo request2; |
| 5077 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5078 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5079 | request2.load_flags = 0; |
| 5080 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5081 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5082 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5083 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5084 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5085 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5086 | // Fetch https://www.example.org/ via HTTP. |
| 5087 | const char get1[] = |
| 5088 | "GET / HTTP/1.1\r\n" |
| 5089 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5090 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5091 | SpdySerializedFrame wrapped_get1( |
| 5092 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5093 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5094 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5095 | SpdySerializedFrame wrapped_get_resp1( |
| 5096 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5097 | SpdySerializedFrame wrapped_body1( |
| 5098 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5099 | SpdySerializedFrame window_update( |
| 5100 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5101 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5102 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5103 | SpdyHeaderBlock connect2_block; |
| 5104 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5105 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5106 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5107 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5108 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5109 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5111 | // Fetch https://mail.example.org/ via HTTP. |
| 5112 | const char get2[] = |
| 5113 | "GET / HTTP/1.1\r\n" |
| 5114 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5115 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5116 | SpdySerializedFrame wrapped_get2( |
| 5117 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5118 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5119 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5120 | SpdySerializedFrame wrapped_get_resp2( |
| 5121 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5122 | SpdySerializedFrame wrapped_body2( |
| 5123 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5124 | |
| 5125 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5126 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5127 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5128 | }; |
| 5129 | |
| 5130 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5131 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5132 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5133 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5134 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5135 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5136 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5137 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5138 | }; |
| 5139 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5140 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5141 | arraysize(spdy_writes)); |
| 5142 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5143 | |
| 5144 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5145 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5147 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5149 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5151 | |
| 5152 | TestCompletionCallback callback; |
| 5153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5155 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5157 | |
| 5158 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5159 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5160 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5162 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5163 | ASSERT_TRUE(response); |
| 5164 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5165 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5166 | |
| 5167 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5168 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5169 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5170 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5172 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5173 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5174 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5175 | |
| 5176 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5177 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5178 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5179 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5180 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5181 | |
| 5182 | // The requests should have different IDs, since they each are using their own |
| 5183 | // separate stream. |
| 5184 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5187 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5191 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5192 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5193 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5194 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5195 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5196 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5197 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5198 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5199 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5200 | |
| 5201 | HttpRequestInfo request1; |
| 5202 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5203 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5204 | request1.load_flags = 0; |
| 5205 | |
| 5206 | HttpRequestInfo request2; |
| 5207 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5208 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5209 | request2.load_flags = 0; |
| 5210 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5211 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5212 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5213 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5214 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5215 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5216 | // Fetch https://www.example.org/ via HTTP. |
| 5217 | const char get1[] = |
| 5218 | "GET / HTTP/1.1\r\n" |
| 5219 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5220 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5221 | SpdySerializedFrame wrapped_get1( |
| 5222 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5223 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5224 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | SpdySerializedFrame wrapped_get_resp1( |
| 5226 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5227 | SpdySerializedFrame wrapped_body1( |
| 5228 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5229 | SpdySerializedFrame window_update( |
| 5230 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5231 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5232 | // Fetch https://www.example.org/2 via HTTP. |
| 5233 | const char get2[] = |
| 5234 | "GET /2 HTTP/1.1\r\n" |
| 5235 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5236 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5237 | SpdySerializedFrame wrapped_get2( |
| 5238 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5239 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5240 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5241 | SpdySerializedFrame wrapped_get_resp2( |
| 5242 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5243 | SpdySerializedFrame wrapped_body2( |
| 5244 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5245 | |
| 5246 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5247 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5248 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5249 | }; |
| 5250 | |
| 5251 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5252 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5253 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5254 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5255 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
| 5256 | CreateMockRead(wrapped_body2, 7, ASYNC), |
| 5257 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5258 | }; |
| 5259 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5260 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5261 | arraysize(spdy_writes)); |
| 5262 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5263 | |
| 5264 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5265 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5267 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5269 | |
| 5270 | TestCompletionCallback callback; |
| 5271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5272 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5273 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5274 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5276 | |
| 5277 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5278 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5279 | |
| 5280 | LoadTimingInfo load_timing_info; |
| 5281 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5282 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5283 | |
| 5284 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5285 | ASSERT_TRUE(response); |
| 5286 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5287 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5288 | |
| 5289 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5290 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5291 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5292 | trans.reset(); |
| 5293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5294 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5295 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5296 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5298 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5301 | |
| 5302 | LoadTimingInfo load_timing_info2; |
| 5303 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5304 | TestLoadTimingReused(load_timing_info2); |
| 5305 | |
| 5306 | // The requests should have the same ID. |
| 5307 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5308 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5309 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5313 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5314 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5315 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5316 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5317 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5318 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5319 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5320 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5321 | |
| 5322 | HttpRequestInfo request1; |
| 5323 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5324 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5325 | request1.load_flags = 0; |
| 5326 | |
| 5327 | HttpRequestInfo request2; |
| 5328 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5329 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5330 | request2.load_flags = 0; |
| 5331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5332 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5333 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5334 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5335 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5336 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5337 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5338 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5339 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5340 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5341 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5342 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5343 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5344 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5345 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5346 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5347 | SpdySerializedFrame body2( |
| 5348 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5349 | |
| 5350 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5352 | }; |
| 5353 | |
| 5354 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5355 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5356 | CreateMockRead(body1, 2, ASYNC), |
| 5357 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5358 | CreateMockRead(body2, 5, ASYNC), |
| 5359 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5360 | }; |
| 5361 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5362 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5363 | arraysize(spdy_writes)); |
| 5364 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5365 | |
| 5366 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5367 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5369 | |
| 5370 | TestCompletionCallback callback; |
| 5371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5372 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5373 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5374 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5375 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5376 | |
| 5377 | LoadTimingInfo load_timing_info; |
| 5378 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5379 | TestLoadTimingNotReused(load_timing_info, |
| 5380 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5381 | |
| 5382 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5383 | ASSERT_TRUE(response); |
| 5384 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5385 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5386 | |
| 5387 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5388 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5389 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5390 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5391 | // Delete the first request, so the second one can reuse the socket. |
| 5392 | trans.reset(); |
| 5393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5394 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5395 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5396 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5397 | |
| 5398 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5399 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5400 | TestLoadTimingReused(load_timing_info2); |
| 5401 | |
| 5402 | // The requests should have the same ID. |
| 5403 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5405 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5406 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5407 | } |
| 5408 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5410 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5411 | HttpRequestInfo request; |
| 5412 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5413 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5414 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5415 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5416 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5417 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5418 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5419 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5420 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5423 | // Since we have proxy, should use full url |
| 5424 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5425 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5426 | "Host: www.example.org\r\n" |
| 5427 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5429 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5430 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5431 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5432 | "Host: www.example.org\r\n" |
| 5433 | "Proxy-Connection: keep-alive\r\n" |
| 5434 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5435 | }; |
| 5436 | |
| 5437 | // The proxy responds to the GET with a 407, using a persistent |
| 5438 | // connection. |
| 5439 | MockRead data_reads1[] = { |
| 5440 | // No credentials. |
| 5441 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5442 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5443 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5444 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5445 | |
| 5446 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5448 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5449 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5450 | }; |
| 5451 | |
| 5452 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5453 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5454 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5455 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5458 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5462 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5464 | |
| 5465 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5467 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5468 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5470 | TestLoadTimingNotReused(load_timing_info, |
| 5471 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5474 | ASSERT_TRUE(response); |
| 5475 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5476 | EXPECT_EQ(407, response->headers->response_code()); |
| 5477 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5478 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5480 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5482 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5484 | |
| 5485 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5487 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5488 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5489 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5490 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5491 | TestLoadTimingReused(load_timing_info); |
| 5492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5494 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5495 | |
| 5496 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5497 | EXPECT_EQ(200, response->headers->response_code()); |
| 5498 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5499 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5500 | |
| 5501 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5502 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5503 | } |
| 5504 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5505 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5506 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5509 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5510 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5511 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5512 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5514 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5515 | // Since we have proxy, should try to establish tunnel. |
| 5516 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5517 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5518 | "Host: www.example.org:443\r\n" |
| 5519 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5520 | }; |
| 5521 | |
| 5522 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5523 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5524 | // No response body because the test stops reading here. |
| 5525 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5526 | }; |
| 5527 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5529 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5532 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5535 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5536 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5538 | |
| 5539 | rv = callback.WaitForResult(); |
| 5540 | EXPECT_EQ(expected_status, rv); |
| 5541 | } |
| 5542 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5543 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5544 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5545 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5546 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5547 | } |
| 5548 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5549 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5550 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5551 | } |
| 5552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5553 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5554 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5555 | } |
| 5556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5558 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5559 | } |
| 5560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5561 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5562 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5563 | } |
| 5564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5565 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5566 | ConnectStatusHelper( |
| 5567 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5568 | } |
| 5569 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5570 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5571 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5572 | } |
| 5573 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5574 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5575 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5576 | } |
| 5577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5578 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5579 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5580 | } |
| 5581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5582 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5583 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5584 | } |
| 5585 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5586 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5587 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5588 | } |
| 5589 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5590 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5591 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5592 | } |
| 5593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5594 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5595 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5596 | } |
| 5597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5598 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5599 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5600 | } |
| 5601 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5602 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5603 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5604 | } |
| 5605 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5606 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5607 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5608 | } |
| 5609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5610 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5611 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5612 | } |
| 5613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5614 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5615 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5616 | } |
| 5617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5618 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5619 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5620 | } |
| 5621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5622 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5623 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5624 | } |
| 5625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5626 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5627 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5628 | } |
| 5629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5630 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5631 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5632 | } |
| 5633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5634 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5635 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5636 | } |
| 5637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5638 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5639 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5640 | } |
| 5641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5642 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5643 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5644 | } |
| 5645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5646 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5647 | ConnectStatusHelperWithExpectedStatus( |
| 5648 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5649 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5650 | } |
| 5651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5652 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5653 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5654 | } |
| 5655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5656 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5658 | } |
| 5659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5661 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5662 | } |
| 5663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5666 | } |
| 5667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5668 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5669 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5670 | } |
| 5671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5672 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5673 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5674 | } |
| 5675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5677 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5678 | } |
| 5679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5680 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5681 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5682 | } |
| 5683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5684 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5685 | ConnectStatusHelper( |
| 5686 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5687 | } |
| 5688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5689 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5690 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5691 | } |
| 5692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5693 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5694 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5695 | } |
| 5696 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5697 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5698 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5699 | } |
| 5700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5701 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5702 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5703 | } |
| 5704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5705 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5706 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5707 | } |
| 5708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5709 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5710 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5711 | } |
| 5712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5713 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5714 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5715 | } |
| 5716 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5717 | // Test the flow when both the proxy server AND origin server require |
| 5718 | // authentication. Again, this uses basic auth for both since that is |
| 5719 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5720 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5721 | HttpRequestInfo request; |
| 5722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5723 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5724 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5725 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5726 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5730 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5731 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5732 | MockWrite( |
| 5733 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5734 | "Host: www.example.org\r\n" |
| 5735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5736 | }; |
| 5737 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5738 | MockRead data_reads1[] = { |
| 5739 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5740 | // Give a couple authenticate options (only the middle one is actually |
| 5741 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5742 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5743 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5744 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5745 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5746 | // Large content-length -- won't matter, as connection will be reset. |
| 5747 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5748 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5749 | }; |
| 5750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5751 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5752 | // request we should be issuing -- the final header line contains the |
| 5753 | // proxy's credentials. |
| 5754 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5755 | MockWrite( |
| 5756 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5757 | "Host: www.example.org\r\n" |
| 5758 | "Proxy-Connection: keep-alive\r\n" |
| 5759 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5760 | }; |
| 5761 | |
| 5762 | // Now the proxy server lets the request pass through to origin server. |
| 5763 | // The origin server responds with a 401. |
| 5764 | MockRead data_reads2[] = { |
| 5765 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5766 | // Note: We are using the same realm-name as the proxy server. This is |
| 5767 | // completely valid, as realms are unique across hosts. |
| 5768 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5769 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5770 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5771 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5772 | }; |
| 5773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5774 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5775 | // the credentials for both the proxy and origin server. |
| 5776 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5777 | MockWrite( |
| 5778 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5779 | "Host: www.example.org\r\n" |
| 5780 | "Proxy-Connection: keep-alive\r\n" |
| 5781 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5782 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5783 | }; |
| 5784 | |
| 5785 | // Lastly we get the desired content. |
| 5786 | MockRead data_reads3[] = { |
| 5787 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5788 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5789 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5791 | }; |
| 5792 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5793 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5794 | data_writes1, arraysize(data_writes1)); |
| 5795 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5796 | data_writes2, arraysize(data_writes2)); |
| 5797 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5798 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5800 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5801 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5803 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5804 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5805 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5807 | |
| 5808 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5809 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5811 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5812 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5813 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5815 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5819 | |
| 5820 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5824 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5825 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5827 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5830 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5832 | |
| 5833 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5837 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5838 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5839 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5840 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5841 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5842 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5843 | // authorization headers. |
| 5844 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5845 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5846 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5847 | // bytes in the debugger. |
| 5848 | |
| 5849 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5850 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5851 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5852 | request.method = "GET"; |
| 5853 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5854 | |
| 5855 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5856 | // to other auth schemes. |
| 5857 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5858 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5859 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5860 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5862 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5863 | MockWrite data_writes1[] = { |
| 5864 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5865 | "Host: 172.22.68.17\r\n" |
| 5866 | "Connection: keep-alive\r\n\r\n"), |
| 5867 | }; |
| 5868 | |
| 5869 | MockRead data_reads1[] = { |
| 5870 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5871 | // Negotiate and NTLM are often requested together. However, we only want |
| 5872 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5873 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5874 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5875 | MockRead("Connection: close\r\n"), |
| 5876 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5877 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5878 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5879 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5880 | }; |
| 5881 | |
| 5882 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5883 | // After restarting with a null identity, this is the |
| 5884 | // request we should be issuing -- the final header line contains a Type |
| 5885 | // 1 message. |
| 5886 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5887 | "Host: 172.22.68.17\r\n" |
| 5888 | "Connection: keep-alive\r\n" |
| 5889 | "Authorization: NTLM " |
| 5890 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5892 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5893 | // (the credentials for the origin server). The second request continues |
| 5894 | // on the same connection. |
| 5895 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5896 | "Host: 172.22.68.17\r\n" |
| 5897 | "Connection: keep-alive\r\n" |
| 5898 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5899 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5900 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5901 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5902 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5903 | }; |
| 5904 | |
| 5905 | MockRead data_reads2[] = { |
| 5906 | // The origin server responds with a Type 2 message. |
| 5907 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5908 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5909 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5910 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5911 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5912 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5913 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5914 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5915 | "BtAAAAAAA=\r\n"), |
| 5916 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5917 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5918 | MockRead("You are not authorized to view this page\r\n"), |
| 5919 | |
| 5920 | // Lastly we get the desired content. |
| 5921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5922 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5923 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5924 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5926 | }; |
| 5927 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5928 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5929 | data_writes1, arraysize(data_writes1)); |
| 5930 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5931 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5933 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5935 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5938 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5939 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5941 | |
| 5942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5945 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5948 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5949 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5951 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5953 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5954 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5956 | |
| 5957 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5960 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5962 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5963 | ASSERT_TRUE(response); |
| 5964 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5966 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5968 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5970 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5971 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5974 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5975 | ASSERT_TRUE(response); |
| 5976 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5977 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5978 | } |
| 5979 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5980 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5981 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5982 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5983 | request.method = "GET"; |
| 5984 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5985 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5986 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5987 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5989 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5990 | MockWrite data_writes1[] = { |
| 5991 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5992 | "Host: 172.22.68.17\r\n" |
| 5993 | "Connection: keep-alive\r\n\r\n"), |
| 5994 | }; |
| 5995 | |
| 5996 | MockRead data_reads1[] = { |
| 5997 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5998 | // Negotiate and NTLM are often requested together. However, we only want |
| 5999 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6000 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6001 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6002 | MockRead("Connection: close\r\n"), |
| 6003 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6004 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6005 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6006 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6007 | }; |
| 6008 | |
| 6009 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6010 | // After restarting with a null identity, this is the |
| 6011 | // request we should be issuing -- the final header line contains a Type |
| 6012 | // 1 message. |
| 6013 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6014 | "Host: 172.22.68.17\r\n" |
| 6015 | "Connection: keep-alive\r\n" |
| 6016 | "Authorization: NTLM " |
| 6017 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6019 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6020 | // (the credentials for the origin server). The second request continues |
| 6021 | // on the same connection. |
| 6022 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6023 | "Host: 172.22.68.17\r\n" |
| 6024 | "Connection: keep-alive\r\n" |
| 6025 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6026 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6027 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6028 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6029 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6030 | }; |
| 6031 | |
| 6032 | MockRead data_reads2[] = { |
| 6033 | // The origin server responds with a Type 2 message. |
| 6034 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6035 | MockRead("WWW-Authenticate: NTLM " |
| 6036 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6037 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6038 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6039 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6040 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6041 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6042 | "BtAAAAAAA=\r\n"), |
| 6043 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6044 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6045 | MockRead("You are not authorized to view this page\r\n"), |
| 6046 | |
| 6047 | // Wrong password. |
| 6048 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6049 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6050 | MockRead("Connection: close\r\n"), |
| 6051 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6052 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6053 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6054 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6055 | }; |
| 6056 | |
| 6057 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6058 | // After restarting with a null identity, this is the |
| 6059 | // request we should be issuing -- the final header line contains a Type |
| 6060 | // 1 message. |
| 6061 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6062 | "Host: 172.22.68.17\r\n" |
| 6063 | "Connection: keep-alive\r\n" |
| 6064 | "Authorization: NTLM " |
| 6065 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6067 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6068 | // (the credentials for the origin server). The second request continues |
| 6069 | // on the same connection. |
| 6070 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6071 | "Host: 172.22.68.17\r\n" |
| 6072 | "Connection: keep-alive\r\n" |
| 6073 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6074 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6075 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6076 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6077 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6078 | }; |
| 6079 | |
| 6080 | MockRead data_reads3[] = { |
| 6081 | // The origin server responds with a Type 2 message. |
| 6082 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6083 | MockRead("WWW-Authenticate: NTLM " |
| 6084 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6085 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6086 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6087 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6088 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6089 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6090 | "BtAAAAAAA=\r\n"), |
| 6091 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6092 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6093 | MockRead("You are not authorized to view this page\r\n"), |
| 6094 | |
| 6095 | // Lastly we get the desired content. |
| 6096 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6097 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6098 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6099 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6101 | }; |
| 6102 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6103 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6104 | data_writes1, arraysize(data_writes1)); |
| 6105 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6106 | data_writes2, arraysize(data_writes2)); |
| 6107 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6108 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6109 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6110 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6111 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6113 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6116 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6117 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6119 | |
| 6120 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6123 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6125 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6126 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6127 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6129 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6130 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6131 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6132 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6133 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6135 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6136 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6137 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6140 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6141 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6143 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6144 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6147 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6148 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6149 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6151 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6152 | |
| 6153 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6155 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6157 | |
| 6158 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6163 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6164 | |
| 6165 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6166 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6168 | |
| 6169 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6170 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6172 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6173 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6174 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6175 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6176 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6177 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6178 | // Test reading a server response which has only headers, and no body. |
| 6179 | // After some maximum number of bytes is consumed, the transaction should |
| 6180 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6181 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6182 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6183 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6184 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6185 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6187 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6188 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6189 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6190 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6191 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6192 | |
| 6193 | MockRead data_reads[] = { |
| 6194 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6195 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6196 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6197 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6198 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6199 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6202 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6203 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6206 | |
| 6207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6208 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6209 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6210 | |
| 6211 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6212 | // establish tunnel. |
| 6213 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6214 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6215 | HttpRequestInfo request; |
| 6216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6217 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6218 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6219 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6220 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6224 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6225 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6226 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6227 | // Since we have proxy, should try to establish tunnel. |
| 6228 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6229 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6230 | "Host: www.example.org:443\r\n" |
| 6231 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6232 | }; |
| 6233 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6234 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6235 | // connection. Usually a proxy would return 501 (not implemented), |
| 6236 | // or 200 (tunnel established). |
| 6237 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6238 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6239 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6240 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6241 | }; |
| 6242 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6244 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6247 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6248 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6249 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6251 | |
| 6252 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6253 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6254 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6255 | // Empty the current queue. This is necessary because idle sockets are |
| 6256 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6257 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6258 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6259 | // We now check to make sure the TCPClientSocket was not added back to |
| 6260 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6261 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6262 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6263 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6264 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6265 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6266 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6267 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6268 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6269 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6270 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6271 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6272 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6273 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6276 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6277 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6278 | MockRead data_reads[] = { |
| 6279 | // A part of the response body is received with the response headers. |
| 6280 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6281 | // The rest of the response body is received in two parts. |
| 6282 | MockRead("lo"), |
| 6283 | MockRead(" world"), |
| 6284 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6286 | }; |
| 6287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6288 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6291 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6292 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6295 | |
| 6296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6297 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6299 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6300 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6301 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6302 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6303 | std::string status_line = response->headers->GetStatusLine(); |
| 6304 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6305 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6306 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6307 | |
| 6308 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6309 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6311 | EXPECT_EQ("hello world", response_data); |
| 6312 | |
| 6313 | // Empty the current queue. This is necessary because idle sockets are |
| 6314 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6315 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6316 | |
| 6317 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6318 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6319 | } |
| 6320 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6321 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6322 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6323 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6324 | HttpRequestInfo request; |
| 6325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6327 | |
| 6328 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6329 | MockWrite( |
| 6330 | "GET / HTTP/1.1\r\n" |
| 6331 | "Host: www.example.org\r\n" |
| 6332 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6333 | }; |
| 6334 | |
| 6335 | MockRead data_reads[] = { |
| 6336 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6337 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6338 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6339 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6340 | }; |
| 6341 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6342 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6344 | |
| 6345 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6346 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6349 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6350 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6352 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6353 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6355 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6357 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6360 | ASSERT_TRUE(response); |
| 6361 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6362 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6363 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6364 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6365 | |
| 6366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6367 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6368 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6369 | EXPECT_EQ("hello world", response_data); |
| 6370 | |
| 6371 | // Empty the current queue. This is necessary because idle sockets are |
| 6372 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6373 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6374 | |
| 6375 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6376 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6380 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6381 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6382 | HttpRequestInfo request; |
| 6383 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6384 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6385 | |
| 6386 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6387 | MockWrite( |
| 6388 | "GET / HTTP/1.1\r\n" |
| 6389 | "Host: www.example.org\r\n" |
| 6390 | "Connection: keep-alive\r\n\r\n"), |
| 6391 | MockWrite( |
| 6392 | "GET / HTTP/1.1\r\n" |
| 6393 | "Host: www.example.org\r\n" |
| 6394 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6395 | }; |
| 6396 | |
| 6397 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6398 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6399 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6400 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6401 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6402 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6404 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6405 | |
| 6406 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6407 | data_writes, arraysize(data_writes)); |
| 6408 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6409 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6411 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6413 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6416 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6417 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6418 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6419 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6420 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6421 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6422 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6423 | |
| 6424 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6425 | ASSERT_TRUE(response); |
| 6426 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6428 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6429 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6430 | |
| 6431 | std::string response_data; |
| 6432 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6434 | EXPECT_EQ("hello world", response_data); |
| 6435 | |
| 6436 | // Empty the current queue. This is necessary because idle sockets are |
| 6437 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6438 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6439 | |
| 6440 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6441 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6442 | |
| 6443 | // Now start the second transaction, which should reuse the previous socket. |
| 6444 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6445 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6446 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6447 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6448 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6450 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6451 | |
| 6452 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6453 | ASSERT_TRUE(response); |
| 6454 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6455 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6456 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6457 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6458 | |
| 6459 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6460 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6461 | EXPECT_EQ("hello world", response_data); |
| 6462 | |
| 6463 | // Empty the current queue. This is necessary because idle sockets are |
| 6464 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6465 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6466 | |
| 6467 | // 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] | 6468 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6469 | } |
| 6470 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6471 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6472 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6473 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6474 | HttpRequestInfo request; |
| 6475 | request.method = "GET"; |
| 6476 | request.url = GURL("http://www.example.org/"); |
| 6477 | request.load_flags = 0; |
| 6478 | |
| 6479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6482 | |
| 6483 | MockRead data_reads[] = { |
| 6484 | // A part of the response body is received with the response headers. |
| 6485 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6486 | // The rest of the response body is received in two parts. |
| 6487 | MockRead("lo"), MockRead(" world"), |
| 6488 | MockRead("junk"), // Should not be read!! |
| 6489 | MockRead(SYNCHRONOUS, OK), |
| 6490 | }; |
| 6491 | |
| 6492 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6494 | |
| 6495 | TestCompletionCallback callback; |
| 6496 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6497 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6499 | |
| 6500 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6503 | ASSERT_TRUE(response); |
| 6504 | EXPECT_TRUE(response->headers); |
| 6505 | std::string status_line = response->headers->GetStatusLine(); |
| 6506 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6507 | |
| 6508 | // Make memory critical notification and ensure the transaction still has been |
| 6509 | // operating right. |
| 6510 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6511 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6512 | base::RunLoop().RunUntilIdle(); |
| 6513 | |
| 6514 | // Socket should not be flushed as long as it is not idle. |
| 6515 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6516 | |
| 6517 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6518 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6519 | EXPECT_THAT(rv, IsOk()); |
| 6520 | EXPECT_EQ("hello world", response_data); |
| 6521 | |
| 6522 | // Empty the current queue. This is necessary because idle sockets are |
| 6523 | // added to the connection pool asynchronously with a PostTask. |
| 6524 | base::RunLoop().RunUntilIdle(); |
| 6525 | |
| 6526 | // We now check to make sure the socket was added back to the pool. |
| 6527 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6528 | |
| 6529 | // Idle sockets should be flushed now. |
| 6530 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6531 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6532 | base::RunLoop().RunUntilIdle(); |
| 6533 | |
| 6534 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6535 | } |
| 6536 | |
| 6537 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6538 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6539 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6540 | HttpRequestInfo request; |
| 6541 | request.method = "GET"; |
| 6542 | request.url = GURL("https://www.example.org/"); |
| 6543 | request.load_flags = 0; |
| 6544 | |
| 6545 | MockWrite data_writes[] = { |
| 6546 | MockWrite("GET / HTTP/1.1\r\n" |
| 6547 | "Host: www.example.org\r\n" |
| 6548 | "Connection: keep-alive\r\n\r\n"), |
| 6549 | }; |
| 6550 | |
| 6551 | MockRead data_reads[] = { |
| 6552 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6553 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6554 | |
| 6555 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6557 | |
| 6558 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6559 | arraysize(data_writes)); |
| 6560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6561 | |
| 6562 | TestCompletionCallback callback; |
| 6563 | |
| 6564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6565 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6566 | |
| 6567 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6568 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6569 | |
| 6570 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6573 | ASSERT_TRUE(response); |
| 6574 | ASSERT_TRUE(response->headers); |
| 6575 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6576 | |
| 6577 | // Make memory critical notification and ensure the transaction still has been |
| 6578 | // operating right. |
| 6579 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6580 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6581 | base::RunLoop().RunUntilIdle(); |
| 6582 | |
| 6583 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6584 | |
| 6585 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6586 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6587 | EXPECT_THAT(rv, IsOk()); |
| 6588 | EXPECT_EQ("hello world", response_data); |
| 6589 | |
| 6590 | // Empty the current queue. This is necessary because idle sockets are |
| 6591 | // added to the connection pool asynchronously with a PostTask. |
| 6592 | base::RunLoop().RunUntilIdle(); |
| 6593 | |
| 6594 | // We now check to make sure the socket was added back to the pool. |
| 6595 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6596 | |
| 6597 | // Make memory notification once again and ensure idle socket is closed. |
| 6598 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6599 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6600 | base::RunLoop().RunUntilIdle(); |
| 6601 | |
| 6602 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6603 | } |
| 6604 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6605 | // Make sure that we recycle a socket after a zero-length response. |
| 6606 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6607 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6608 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6609 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6610 | request.url = GURL( |
| 6611 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6612 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6613 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6614 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6615 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6617 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6618 | MockRead data_reads[] = { |
| 6619 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6620 | "Content-Length: 0\r\n" |
| 6621 | "Content-Type: text/html\r\n\r\n"), |
| 6622 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6624 | }; |
| 6625 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6626 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6628 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6629 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6630 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6633 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6634 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6637 | |
| 6638 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6639 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6641 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6642 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6643 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6644 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6645 | std::string status_line = response->headers->GetStatusLine(); |
| 6646 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6647 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6648 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6649 | |
| 6650 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6651 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6652 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6653 | EXPECT_EQ("", response_data); |
| 6654 | |
| 6655 | // Empty the current queue. This is necessary because idle sockets are |
| 6656 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6657 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6658 | |
| 6659 | // 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] | 6660 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6661 | } |
| 6662 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6663 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6664 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6665 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6666 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6667 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6668 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6669 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6670 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6671 | // after use. |
| 6672 | request[0].method = "GET"; |
| 6673 | request[0].url = GURL("http://www.google.com/"); |
| 6674 | request[0].load_flags = 0; |
| 6675 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6676 | // transaction 1. The first attempts fails when writing the POST data. |
| 6677 | // This causes the transaction to retry with a new socket. The second |
| 6678 | // attempt succeeds. |
| 6679 | request[1].method = "POST"; |
| 6680 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6681 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6682 | request[1].load_flags = 0; |
| 6683 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6685 | |
| 6686 | // The first socket is used for transaction 1 and the first attempt of |
| 6687 | // transaction 2. |
| 6688 | |
| 6689 | // The response of transaction 1. |
| 6690 | MockRead data_reads1[] = { |
| 6691 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6692 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6693 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6694 | }; |
| 6695 | // The mock write results of transaction 1 and the first attempt of |
| 6696 | // transaction 2. |
| 6697 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6698 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6699 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6700 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6701 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6702 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6703 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6704 | |
| 6705 | // The second socket is used for the second attempt of transaction 2. |
| 6706 | |
| 6707 | // The response of transaction 2. |
| 6708 | MockRead data_reads2[] = { |
| 6709 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6710 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6712 | }; |
| 6713 | // The mock write results of the second attempt of transaction 2. |
| 6714 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6715 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6716 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6717 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6718 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6719 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6720 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6721 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6722 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6723 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6724 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6725 | "hello world", "welcome" |
| 6726 | }; |
| 6727 | |
| 6728 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6731 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6732 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6733 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6735 | |
| 6736 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6737 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6739 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6740 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6741 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6742 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6743 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6744 | |
| 6745 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6746 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6748 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6749 | } |
| 6750 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6751 | |
| 6752 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6753 | // 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] | 6754 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6755 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6756 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6758 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6759 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6763 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6764 | // The password contains an escaped character -- for this test to pass it |
| 6765 | // will need to be unescaped by HttpNetworkTransaction. |
| 6766 | EXPECT_EQ("b%40r", request.url.password()); |
| 6767 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6768 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6769 | MockWrite( |
| 6770 | "GET / HTTP/1.1\r\n" |
| 6771 | "Host: www.example.org\r\n" |
| 6772 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6773 | }; |
| 6774 | |
| 6775 | MockRead data_reads1[] = { |
| 6776 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6777 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6778 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6779 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6780 | }; |
| 6781 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6782 | // After the challenge above, the transaction will be restarted using the |
| 6783 | // identity from the url (foo, b@r) to answer the challenge. |
| 6784 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6785 | MockWrite( |
| 6786 | "GET / HTTP/1.1\r\n" |
| 6787 | "Host: www.example.org\r\n" |
| 6788 | "Connection: keep-alive\r\n" |
| 6789 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6790 | }; |
| 6791 | |
| 6792 | MockRead data_reads2[] = { |
| 6793 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6794 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6795 | MockRead(SYNCHRONOUS, OK), |
| 6796 | }; |
| 6797 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6798 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6799 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6800 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6801 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6802 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6803 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6805 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6806 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6808 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6809 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6810 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6811 | |
| 6812 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6813 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6815 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6816 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6817 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6819 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6820 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6821 | |
| 6822 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6823 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6824 | |
| 6825 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6826 | |
| 6827 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6828 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6832 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6833 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6834 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6835 | HttpRequestInfo request; |
| 6836 | request.method = "GET"; |
| 6837 | // Note: the URL has a username:password in it. The password "baz" is |
| 6838 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6839 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6840 | |
| 6841 | request.load_flags = LOAD_NORMAL; |
| 6842 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6845 | |
| 6846 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6847 | MockWrite( |
| 6848 | "GET / HTTP/1.1\r\n" |
| 6849 | "Host: www.example.org\r\n" |
| 6850 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6851 | }; |
| 6852 | |
| 6853 | MockRead data_reads1[] = { |
| 6854 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6855 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6856 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6857 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6858 | }; |
| 6859 | |
| 6860 | // After the challenge above, the transaction will be restarted using the |
| 6861 | // identity from the url (foo, baz) to answer the challenge. |
| 6862 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6863 | MockWrite( |
| 6864 | "GET / HTTP/1.1\r\n" |
| 6865 | "Host: www.example.org\r\n" |
| 6866 | "Connection: keep-alive\r\n" |
| 6867 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6868 | }; |
| 6869 | |
| 6870 | MockRead data_reads2[] = { |
| 6871 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6872 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6873 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6874 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6875 | }; |
| 6876 | |
| 6877 | // After the challenge above, the transaction will be restarted using the |
| 6878 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6879 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6880 | MockWrite( |
| 6881 | "GET / HTTP/1.1\r\n" |
| 6882 | "Host: www.example.org\r\n" |
| 6883 | "Connection: keep-alive\r\n" |
| 6884 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6885 | }; |
| 6886 | |
| 6887 | MockRead data_reads3[] = { |
| 6888 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6889 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6890 | MockRead(SYNCHRONOUS, OK), |
| 6891 | }; |
| 6892 | |
| 6893 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6894 | data_writes1, arraysize(data_writes1)); |
| 6895 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6896 | data_writes2, arraysize(data_writes2)); |
| 6897 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6898 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6901 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6902 | |
| 6903 | TestCompletionCallback callback1; |
| 6904 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6905 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6907 | |
| 6908 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6911 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6912 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6913 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6915 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6916 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6917 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6919 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6920 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6921 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6922 | |
| 6923 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6924 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6926 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6927 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6928 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6930 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6931 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6932 | |
| 6933 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6934 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6935 | |
| 6936 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6937 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6938 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6939 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6940 | } |
| 6941 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6942 | |
| 6943 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6944 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6945 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6947 | HttpRequestInfo request; |
| 6948 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6949 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6950 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6951 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6953 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6954 | |
| 6955 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6956 | MockWrite( |
| 6957 | "GET / HTTP/1.1\r\n" |
| 6958 | "Host: www.example.org\r\n" |
| 6959 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6960 | }; |
| 6961 | |
| 6962 | MockRead data_reads1[] = { |
| 6963 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6964 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6965 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6966 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6967 | }; |
| 6968 | |
| 6969 | // After the challenge above, the transaction will be restarted using the |
| 6970 | // identity supplied by the user, not the one in the URL, to answer the |
| 6971 | // challenge. |
| 6972 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6973 | MockWrite( |
| 6974 | "GET / HTTP/1.1\r\n" |
| 6975 | "Host: www.example.org\r\n" |
| 6976 | "Connection: keep-alive\r\n" |
| 6977 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6978 | }; |
| 6979 | |
| 6980 | MockRead data_reads3[] = { |
| 6981 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6982 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6983 | MockRead(SYNCHRONOUS, OK), |
| 6984 | }; |
| 6985 | |
| 6986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6987 | data_writes1, arraysize(data_writes1)); |
| 6988 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6989 | data_writes3, arraysize(data_writes3)); |
| 6990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6992 | |
| 6993 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6994 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6996 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6997 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6998 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7000 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7001 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7002 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7003 | |
| 7004 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7005 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7007 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7008 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7009 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7011 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7012 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7013 | |
| 7014 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7015 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7016 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7017 | |
| 7018 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7019 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7020 | } |
| 7021 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7022 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7023 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7025 | |
| 7026 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7027 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7028 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7030 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7033 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7034 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7035 | MockWrite( |
| 7036 | "GET /x/y/z HTTP/1.1\r\n" |
| 7037 | "Host: www.example.org\r\n" |
| 7038 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7039 | }; |
| 7040 | |
| 7041 | MockRead data_reads1[] = { |
| 7042 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7043 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7044 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7045 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7046 | }; |
| 7047 | |
| 7048 | // Resend with authorization (username=foo, password=bar) |
| 7049 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7050 | MockWrite( |
| 7051 | "GET /x/y/z HTTP/1.1\r\n" |
| 7052 | "Host: www.example.org\r\n" |
| 7053 | "Connection: keep-alive\r\n" |
| 7054 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7055 | }; |
| 7056 | |
| 7057 | // Sever accepts the authorization. |
| 7058 | MockRead data_reads2[] = { |
| 7059 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7060 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7062 | }; |
| 7063 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7064 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7065 | data_writes1, arraysize(data_writes1)); |
| 7066 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7067 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7069 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7071 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7072 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7073 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7075 | |
| 7076 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7077 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7079 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7080 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7081 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7083 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7085 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7086 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | |
| 7089 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7092 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7093 | ASSERT_TRUE(response); |
| 7094 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7095 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7096 | } |
| 7097 | |
| 7098 | // ------------------------------------------------------------------------ |
| 7099 | |
| 7100 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7101 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7102 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7103 | request.method = "GET"; |
| 7104 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7105 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7106 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7108 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7109 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7110 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7111 | MockWrite( |
| 7112 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7113 | "Host: www.example.org\r\n" |
| 7114 | "Connection: keep-alive\r\n" |
| 7115 | // Send preemptive authorization for MyRealm1 |
| 7116 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7117 | }; |
| 7118 | |
| 7119 | // The server didn't like the preemptive authorization, and |
| 7120 | // challenges us for a different realm (MyRealm2). |
| 7121 | MockRead data_reads1[] = { |
| 7122 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7123 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7124 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7125 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7126 | }; |
| 7127 | |
| 7128 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7129 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7130 | MockWrite( |
| 7131 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7132 | "Host: www.example.org\r\n" |
| 7133 | "Connection: keep-alive\r\n" |
| 7134 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7135 | }; |
| 7136 | |
| 7137 | // Sever accepts the authorization. |
| 7138 | MockRead data_reads2[] = { |
| 7139 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7140 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7141 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7142 | }; |
| 7143 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7144 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7145 | data_writes1, arraysize(data_writes1)); |
| 7146 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7147 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7148 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7149 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7151 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7152 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7153 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7155 | |
| 7156 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7157 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7159 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7160 | ASSERT_TRUE(response); |
| 7161 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7162 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7163 | EXPECT_EQ("http://www.example.org", |
| 7164 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7165 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7166 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7167 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7168 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7170 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7171 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
| 7174 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7175 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7177 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7178 | ASSERT_TRUE(response); |
| 7179 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7180 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7181 | } |
| 7182 | |
| 7183 | // ------------------------------------------------------------------------ |
| 7184 | |
| 7185 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7186 | // succeed with preemptive authorization. |
| 7187 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7188 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7190 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7192 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7193 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7194 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7195 | MockWrite( |
| 7196 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7197 | "Host: www.example.org\r\n" |
| 7198 | "Connection: keep-alive\r\n" |
| 7199 | // The authorization for MyRealm1 gets sent preemptively |
| 7200 | // (since the url is in the same protection space) |
| 7201 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7202 | }; |
| 7203 | |
| 7204 | // Sever accepts the preemptive authorization |
| 7205 | MockRead data_reads1[] = { |
| 7206 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7207 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7208 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7209 | }; |
| 7210 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7211 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7212 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7213 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7215 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7216 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7217 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7219 | |
| 7220 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7221 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7223 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7224 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7225 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7226 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7227 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7228 | } |
| 7229 | |
| 7230 | // ------------------------------------------------------------------------ |
| 7231 | |
| 7232 | // Transaction 4: request another URL in MyRealm (however the |
| 7233 | // url is not known to belong to the protection space, so no pre-auth). |
| 7234 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7235 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7236 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7237 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7240 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7241 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7242 | MockWrite( |
| 7243 | "GET /x/1 HTTP/1.1\r\n" |
| 7244 | "Host: www.example.org\r\n" |
| 7245 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7246 | }; |
| 7247 | |
| 7248 | MockRead data_reads1[] = { |
| 7249 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7250 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7251 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7252 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7253 | }; |
| 7254 | |
| 7255 | // Resend with authorization from MyRealm's cache. |
| 7256 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7257 | MockWrite( |
| 7258 | "GET /x/1 HTTP/1.1\r\n" |
| 7259 | "Host: www.example.org\r\n" |
| 7260 | "Connection: keep-alive\r\n" |
| 7261 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7262 | }; |
| 7263 | |
| 7264 | // Sever accepts the authorization. |
| 7265 | MockRead data_reads2[] = { |
| 7266 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7267 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7268 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7269 | }; |
| 7270 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7271 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7272 | data_writes1, arraysize(data_writes1)); |
| 7273 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7274 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7275 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7276 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7278 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7279 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7280 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7282 | |
| 7283 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7286 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7287 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7288 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7290 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7291 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7294 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7295 | ASSERT_TRUE(response); |
| 7296 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7297 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7298 | } |
| 7299 | |
| 7300 | // ------------------------------------------------------------------------ |
| 7301 | |
| 7302 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7303 | // cached identity. Should invalidate and re-prompt. |
| 7304 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7305 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7307 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7310 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7311 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7312 | MockWrite( |
| 7313 | "GET /p/q/t HTTP/1.1\r\n" |
| 7314 | "Host: www.example.org\r\n" |
| 7315 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7316 | }; |
| 7317 | |
| 7318 | MockRead data_reads1[] = { |
| 7319 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7320 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7321 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7322 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7323 | }; |
| 7324 | |
| 7325 | // Resend with authorization from cache for MyRealm. |
| 7326 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7327 | MockWrite( |
| 7328 | "GET /p/q/t HTTP/1.1\r\n" |
| 7329 | "Host: www.example.org\r\n" |
| 7330 | "Connection: keep-alive\r\n" |
| 7331 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7332 | }; |
| 7333 | |
| 7334 | // Sever rejects the authorization. |
| 7335 | MockRead data_reads2[] = { |
| 7336 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7337 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7338 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7339 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7340 | }; |
| 7341 | |
| 7342 | // At this point we should prompt for new credentials for MyRealm. |
| 7343 | // Restart with username=foo3, password=foo4. |
| 7344 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7345 | MockWrite( |
| 7346 | "GET /p/q/t HTTP/1.1\r\n" |
| 7347 | "Host: www.example.org\r\n" |
| 7348 | "Connection: keep-alive\r\n" |
| 7349 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7350 | }; |
| 7351 | |
| 7352 | // Sever accepts the authorization. |
| 7353 | MockRead data_reads3[] = { |
| 7354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7355 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7356 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7357 | }; |
| 7358 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7359 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7360 | data_writes1, arraysize(data_writes1)); |
| 7361 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7362 | data_writes2, arraysize(data_writes2)); |
| 7363 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7364 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7365 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7366 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7367 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7369 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7370 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7371 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7373 | |
| 7374 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7377 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7378 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7379 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7381 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7382 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7385 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7386 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7387 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7389 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7392 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7394 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7395 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7399 | ASSERT_TRUE(response); |
| 7400 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7401 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7402 | } |
| 7403 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7404 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7405 | // Tests that nonce count increments when multiple auth attempts |
| 7406 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7407 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7408 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7409 | new HttpAuthHandlerDigest::Factory(); |
| 7410 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7411 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7412 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7413 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7414 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7415 | |
| 7416 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7417 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7418 | HttpRequestInfo request; |
| 7419 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7420 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7422 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7423 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7424 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7425 | MockWrite( |
| 7426 | "GET /x/y/z HTTP/1.1\r\n" |
| 7427 | "Host: www.example.org\r\n" |
| 7428 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7429 | }; |
| 7430 | |
| 7431 | MockRead data_reads1[] = { |
| 7432 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7433 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7434 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7435 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7436 | }; |
| 7437 | |
| 7438 | // Resend with authorization (username=foo, password=bar) |
| 7439 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7440 | MockWrite( |
| 7441 | "GET /x/y/z HTTP/1.1\r\n" |
| 7442 | "Host: www.example.org\r\n" |
| 7443 | "Connection: keep-alive\r\n" |
| 7444 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7445 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7446 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7447 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7448 | }; |
| 7449 | |
| 7450 | // Sever accepts the authorization. |
| 7451 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7452 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7453 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7454 | }; |
| 7455 | |
| 7456 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7457 | data_writes1, arraysize(data_writes1)); |
| 7458 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7459 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7460 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7461 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7463 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7464 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7465 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7467 | |
| 7468 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7471 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7472 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7473 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7475 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7477 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7478 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7480 | |
| 7481 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7485 | ASSERT_TRUE(response); |
| 7486 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7487 | } |
| 7488 | |
| 7489 | // ------------------------------------------------------------------------ |
| 7490 | |
| 7491 | // Transaction 2: Request another resource in digestive's protection space. |
| 7492 | // This will preemptively add an Authorization header which should have an |
| 7493 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7494 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7495 | HttpRequestInfo request; |
| 7496 | request.method = "GET"; |
| 7497 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7498 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7499 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7502 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7503 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | MockWrite( |
| 7505 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7506 | "Host: www.example.org\r\n" |
| 7507 | "Connection: keep-alive\r\n" |
| 7508 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7509 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7510 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7511 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7512 | }; |
| 7513 | |
| 7514 | // Sever accepts the authorization. |
| 7515 | MockRead data_reads1[] = { |
| 7516 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7517 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7518 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7522 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7523 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7524 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7525 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7526 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7527 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7529 | |
| 7530 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7531 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7533 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7534 | ASSERT_TRUE(response); |
| 7535 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7536 | } |
| 7537 | } |
| 7538 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7539 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7540 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7541 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7544 | |
| 7545 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7546 | trans.read_buf_ = new IOBuffer(15); |
| 7547 | trans.read_buf_len_ = 15; |
| 7548 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7549 | |
| 7550 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7551 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7552 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7553 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7554 | response->response_time = base::Time::Now(); |
| 7555 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7556 | |
| 7557 | { // Setup state for response_.vary_data |
| 7558 | HttpRequestInfo request; |
| 7559 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7560 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7561 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7562 | request.extra_headers.SetHeader("Foo", "1"); |
| 7563 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7564 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7565 | } |
| 7566 | |
| 7567 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7568 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7569 | |
| 7570 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7571 | EXPECT_FALSE(trans.read_buf_); |
| 7572 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7573 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7574 | EXPECT_FALSE(response->auth_challenge); |
| 7575 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7576 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7577 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7578 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7579 | } |
| 7580 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7581 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7582 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7583 | HttpRequestInfo request; |
| 7584 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7585 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7589 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7590 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7591 | MockWrite( |
| 7592 | "GET / HTTP/1.1\r\n" |
| 7593 | "Host: www.example.org\r\n" |
| 7594 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7595 | }; |
| 7596 | |
| 7597 | MockRead data_reads[] = { |
| 7598 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7599 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7600 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7602 | }; |
| 7603 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7604 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7605 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7606 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7607 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7608 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7609 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7610 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7615 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7616 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7617 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7619 | |
| 7620 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7621 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7622 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7623 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7625 | |
| 7626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7629 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7630 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7631 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7632 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7633 | } |
| 7634 | |
| 7635 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7636 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7637 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7638 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7639 | |
| 7640 | HttpRequestInfo request; |
| 7641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7642 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7643 | |
| 7644 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7645 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7646 | "Host: www.example.org:443\r\n" |
| 7647 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7648 | }; |
| 7649 | |
| 7650 | MockRead proxy_reads[] = { |
| 7651 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7652 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7653 | }; |
| 7654 | |
| 7655 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7656 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7657 | "Host: www.example.org:443\r\n" |
| 7658 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7659 | MockWrite("GET / HTTP/1.1\r\n" |
| 7660 | "Host: www.example.org\r\n" |
| 7661 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7662 | }; |
| 7663 | |
| 7664 | MockRead data_reads[] = { |
| 7665 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7666 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7667 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7668 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7669 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7670 | }; |
| 7671 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7672 | StaticSocketDataProvider ssl_bad_certificate( |
| 7673 | proxy_reads, arraysize(proxy_reads), |
| 7674 | proxy_writes, arraysize(proxy_writes)); |
| 7675 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7676 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7677 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7678 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7679 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7680 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7685 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7686 | |
| 7687 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7688 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7689 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7691 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7692 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7693 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7695 | |
| 7696 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7697 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7698 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7699 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7701 | |
| 7702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7703 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7705 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7706 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7707 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7708 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7709 | } |
| 7710 | } |
| 7711 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7712 | |
| 7713 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7714 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7715 | session_deps_.proxy_service = |
| 7716 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7717 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7718 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7719 | |
| 7720 | HttpRequestInfo request; |
| 7721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7722 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7723 | |
| 7724 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7725 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7726 | "Host: www.example.org:443\r\n" |
| 7727 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7728 | MockWrite("GET / HTTP/1.1\r\n" |
| 7729 | "Host: www.example.org\r\n" |
| 7730 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7731 | }; |
| 7732 | |
| 7733 | MockRead data_reads[] = { |
| 7734 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7735 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7736 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7737 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7738 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7739 | }; |
| 7740 | |
| 7741 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7742 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7743 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7744 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7750 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7754 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7757 | |
| 7758 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7759 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7760 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7761 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7762 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7763 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7764 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7765 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7766 | EXPECT_EQ(200, response->headers->response_code()); |
| 7767 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7768 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7769 | |
| 7770 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7771 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7772 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7773 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7774 | } |
| 7775 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7776 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7777 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7778 | session_deps_.proxy_service = |
| 7779 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7780 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7781 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7782 | |
| 7783 | HttpRequestInfo request; |
| 7784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7785 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7786 | |
| 7787 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7788 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7789 | "Host: www.example.org:443\r\n" |
| 7790 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7791 | }; |
| 7792 | |
| 7793 | MockRead data_reads[] = { |
| 7794 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7795 | MockRead("Location: http://login.example.com/\r\n"), |
| 7796 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7798 | }; |
| 7799 | |
| 7800 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7801 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7802 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7803 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7807 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7811 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7814 | |
| 7815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7816 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7818 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7819 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7820 | |
| 7821 | EXPECT_EQ(302, response->headers->response_code()); |
| 7822 | std::string url; |
| 7823 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7824 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7825 | |
| 7826 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7827 | // timing for the proxy connection instead of the connection to the host, |
| 7828 | // and no send / receive times. |
| 7829 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7830 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7831 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7832 | |
| 7833 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7834 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7835 | |
| 7836 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7837 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7838 | load_timing_info.proxy_resolve_end); |
| 7839 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7840 | load_timing_info.connect_timing.connect_start); |
| 7841 | ExpectConnectTimingHasTimes( |
| 7842 | load_timing_info.connect_timing, |
| 7843 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7844 | |
| 7845 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7846 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7847 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7851 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7852 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7853 | |
| 7854 | HttpRequestInfo request; |
| 7855 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7856 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7857 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7858 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7859 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7860 | SpdySerializedFrame goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7861 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7862 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7863 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7864 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7865 | }; |
| 7866 | |
| 7867 | static const char* const kExtraHeaders[] = { |
| 7868 | "location", |
| 7869 | "http://login.example.com/", |
| 7870 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7871 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7872 | "302 Redirect", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7873 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7874 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7875 | }; |
| 7876 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7877 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7878 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7879 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7880 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7881 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7885 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7886 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7888 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7889 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7890 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7892 | |
| 7893 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7894 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7895 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7896 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7897 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7898 | |
| 7899 | EXPECT_EQ(302, response->headers->response_code()); |
| 7900 | std::string url; |
| 7901 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7902 | EXPECT_EQ("http://login.example.com/", url); |
| 7903 | } |
| 7904 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7905 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7906 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7907 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7908 | |
| 7909 | HttpRequestInfo request; |
| 7910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7911 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7912 | |
| 7913 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7914 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7915 | "Host: www.example.org:443\r\n" |
| 7916 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7917 | }; |
| 7918 | |
| 7919 | MockRead data_reads[] = { |
| 7920 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7921 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7922 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7924 | }; |
| 7925 | |
| 7926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7927 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7928 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7929 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7933 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7934 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7936 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7937 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7938 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7940 | |
| 7941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7942 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7943 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7944 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7945 | } |
| 7946 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7947 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7948 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7949 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7950 | |
| 7951 | HttpRequestInfo request; |
| 7952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7953 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7954 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7955 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7956 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7957 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7958 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7959 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7960 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7961 | }; |
| 7962 | |
| 7963 | static const char* const kExtraHeaders[] = { |
| 7964 | "location", |
| 7965 | "http://login.example.com/", |
| 7966 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7967 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7968 | "404 Not Found", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
| 7969 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7970 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7971 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7972 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7973 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7974 | }; |
| 7975 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7976 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7977 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7978 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7979 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7980 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7984 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7985 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7987 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7988 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7989 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7991 | |
| 7992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7993 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7994 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7995 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7996 | } |
| 7997 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7998 | // Test the request-challenge-retry sequence for basic auth, through |
| 7999 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8000 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8001 | HttpRequestInfo request; |
| 8002 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8003 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8004 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8005 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8006 | |
| 8007 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8008 | session_deps_.proxy_service = |
| 8009 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8010 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8011 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8013 | |
| 8014 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8015 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8016 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8017 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8018 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8019 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8021 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8022 | // be issuing -- the final header line contains the credentials. |
| 8023 | const char* const kAuthCredentials[] = { |
| 8024 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8025 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8026 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8027 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8028 | HostPortPair("www.example.org", 443))); |
| 8029 | // fetch https://www.example.org/ via HTTP |
| 8030 | const char get[] = |
| 8031 | "GET / HTTP/1.1\r\n" |
| 8032 | "Host: www.example.org\r\n" |
| 8033 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8034 | SpdySerializedFrame wrapped_get( |
| 8035 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8036 | |
| 8037 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8038 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8039 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8040 | }; |
| 8041 | |
| 8042 | // The proxy responds to the connect with a 407, using a persistent |
| 8043 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8044 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8045 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8046 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8047 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8048 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8049 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8050 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8051 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8052 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8053 | "Content-Length: 5\r\n\r\n"; |
| 8054 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8055 | SpdySerializedFrame wrapped_get_resp( |
| 8056 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8057 | SpdySerializedFrame wrapped_body( |
| 8058 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8059 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8060 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8061 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8062 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8063 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8064 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8065 | }; |
| 8066 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8067 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8068 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8069 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8070 | // Negotiate SPDY to the proxy |
| 8071 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8072 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8073 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8074 | // Vanilla SSL to the server |
| 8075 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8076 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8077 | |
| 8078 | TestCompletionCallback callback1; |
| 8079 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8080 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8082 | |
| 8083 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8085 | |
| 8086 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8087 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8088 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8089 | log.GetEntries(&entries); |
| 8090 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8091 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8092 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8093 | ExpectLogContainsSomewhere( |
| 8094 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8095 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8096 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8097 | |
| 8098 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8099 | ASSERT_TRUE(response); |
| 8100 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8101 | EXPECT_EQ(407, response->headers->response_code()); |
| 8102 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8103 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8104 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8105 | |
| 8106 | TestCompletionCallback callback2; |
| 8107 | |
| 8108 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8109 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8111 | |
| 8112 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8114 | |
| 8115 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8116 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8117 | |
| 8118 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8119 | EXPECT_EQ(200, response->headers->response_code()); |
| 8120 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8121 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8122 | |
| 8123 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8124 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8125 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8126 | LoadTimingInfo load_timing_info; |
| 8127 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8128 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8129 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8130 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8131 | trans.reset(); |
| 8132 | session->CloseAllConnections(); |
| 8133 | } |
| 8134 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8135 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8136 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8137 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8138 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8139 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8140 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8141 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8142 | HttpRequestInfo request; |
| 8143 | HttpRequestInfo push_request; |
| 8144 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8145 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8146 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8147 | push_request.method = "GET"; |
| 8148 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8149 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8150 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8151 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8152 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8153 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8154 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8155 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8156 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8159 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8160 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8161 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8162 | |
| 8163 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8164 | CreateMockWrite(stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8165 | }; |
| 8166 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8167 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8168 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8169 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8170 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8171 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8172 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8173 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8174 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8175 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8176 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8177 | |
| 8178 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8179 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8180 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8181 | CreateMockRead(stream1_body, 3, ASYNC), |
| 8182 | CreateMockRead(stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8183 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8184 | }; |
| 8185 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8186 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8187 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8188 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8189 | // Negotiate SPDY to the proxy |
| 8190 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8191 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8192 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8194 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8196 | TestCompletionCallback callback; |
| 8197 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8198 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8199 | |
| 8200 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8201 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8202 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8204 | std::unique_ptr<HttpNetworkTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8206 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8208 | |
| 8209 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8210 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8211 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8212 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8213 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8214 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8215 | |
| 8216 | EXPECT_EQ(200, response->headers->response_code()); |
| 8217 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8218 | |
| 8219 | std::string response_data; |
| 8220 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8221 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8222 | EXPECT_EQ("hello!", response_data); |
| 8223 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8224 | LoadTimingInfo load_timing_info; |
| 8225 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8226 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8227 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8228 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8229 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8230 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8231 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8232 | |
| 8233 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8234 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8235 | EXPECT_EQ("pushed", response_data); |
| 8236 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8237 | LoadTimingInfo push_load_timing_info; |
| 8238 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8239 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8240 | // The transactions should share a socket ID, despite being for different |
| 8241 | // origins. |
| 8242 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8243 | push_load_timing_info.socket_log_id); |
| 8244 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8245 | trans.reset(); |
| 8246 | push_trans.reset(); |
| 8247 | session->CloseAllConnections(); |
| 8248 | } |
| 8249 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8250 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8251 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8252 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8253 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8254 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8255 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8256 | HttpRequestInfo request; |
| 8257 | |
| 8258 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8259 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8260 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8261 | session_deps_.proxy_service = |
| 8262 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8263 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8264 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8265 | |
| 8266 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8267 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8268 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8270 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8271 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8272 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8273 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8274 | SpdySerializedFrame push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8275 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8276 | |
| 8277 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8278 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8279 | }; |
| 8280 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8281 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8282 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8283 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8284 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8285 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8286 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8287 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8288 | |
| 8289 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8290 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8291 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8292 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8293 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8294 | }; |
| 8295 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8296 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8297 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8298 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8299 | // Negotiate SPDY to the proxy |
| 8300 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8301 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8304 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8306 | TestCompletionCallback callback; |
| 8307 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8309 | |
| 8310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8312 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8313 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8314 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8315 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8316 | |
| 8317 | EXPECT_EQ(200, response->headers->response_code()); |
| 8318 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8319 | |
| 8320 | std::string response_data; |
| 8321 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8323 | EXPECT_EQ("hello!", response_data); |
| 8324 | |
| 8325 | trans.reset(); |
| 8326 | session->CloseAllConnections(); |
| 8327 | } |
| 8328 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8329 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8330 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8331 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8332 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8333 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8334 | proxy_delegate->set_trusted_spdy_proxy( |
| 8335 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8336 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8337 | HttpRequestInfo request; |
| 8338 | |
| 8339 | request.method = "GET"; |
| 8340 | request.url = GURL("http://www.example.org/"); |
| 8341 | |
| 8342 | // Configure against https proxy server "myproxy:70". |
| 8343 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8344 | BoundTestNetLog log; |
| 8345 | session_deps_.net_log = log.bound().net_log(); |
| 8346 | |
| 8347 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8348 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8351 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8352 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8353 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8354 | |
| 8355 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8356 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8357 | }; |
| 8358 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8359 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8360 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8361 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8362 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8363 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8364 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8365 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8366 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8367 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8368 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8369 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8370 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8371 | |
| 8372 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8373 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8374 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8375 | CreateMockRead(stream1_body, 3, ASYNC), |
| 8376 | CreateMockRead(stream2_body, 4, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8377 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 8378 | }; |
| 8379 | |
| 8380 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8381 | arraysize(spdy_writes)); |
| 8382 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8383 | // Negotiate SPDY to the proxy |
| 8384 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8385 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8388 | std::unique_ptr<HttpNetworkTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8389 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8390 | TestCompletionCallback callback; |
| 8391 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8393 | |
| 8394 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8395 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8396 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8397 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8398 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8399 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8400 | |
| 8401 | EXPECT_EQ(200, response->headers->response_code()); |
| 8402 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8403 | |
| 8404 | std::string response_data; |
| 8405 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8406 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8407 | EXPECT_EQ("hello!", response_data); |
| 8408 | |
| 8409 | trans.reset(); |
| 8410 | session->CloseAllConnections(); |
| 8411 | } |
| 8412 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8413 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8414 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8415 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8416 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8417 | |
| 8418 | HttpRequestInfo request; |
| 8419 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8420 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8421 | |
| 8422 | // Attempt to fetch the URL from a server with a bad cert |
| 8423 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8424 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8425 | "Host: www.example.org:443\r\n" |
| 8426 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8427 | }; |
| 8428 | |
| 8429 | MockRead bad_cert_reads[] = { |
| 8430 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8431 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8432 | }; |
| 8433 | |
| 8434 | // Attempt to fetch the URL with a good cert |
| 8435 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8436 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8437 | "Host: www.example.org:443\r\n" |
| 8438 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8439 | MockWrite("GET / HTTP/1.1\r\n" |
| 8440 | "Host: www.example.org\r\n" |
| 8441 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8442 | }; |
| 8443 | |
| 8444 | MockRead good_cert_reads[] = { |
| 8445 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8446 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8448 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8449 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8450 | }; |
| 8451 | |
| 8452 | StaticSocketDataProvider ssl_bad_certificate( |
| 8453 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8454 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8455 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8456 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8457 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8458 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8459 | |
| 8460 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8462 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8464 | |
| 8465 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8470 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8471 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8474 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8475 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8477 | |
| 8478 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8479 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8481 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8483 | |
| 8484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8488 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8489 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8490 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8491 | } |
| 8492 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8493 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8494 | HttpRequestInfo request; |
| 8495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8496 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8497 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8498 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8499 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8502 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8503 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8504 | MockWrite( |
| 8505 | "GET / HTTP/1.1\r\n" |
| 8506 | "Host: www.example.org\r\n" |
| 8507 | "Connection: keep-alive\r\n" |
| 8508 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8509 | }; |
| 8510 | |
| 8511 | // Lastly, the server responds with the actual content. |
| 8512 | MockRead data_reads[] = { |
| 8513 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8514 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8515 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8516 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8517 | }; |
| 8518 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8519 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8520 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8521 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8522 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8523 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8524 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8525 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8527 | |
| 8528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8529 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8530 | } |
| 8531 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8532 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8533 | HttpRequestInfo request; |
| 8534 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8535 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8536 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8537 | "Chromium Ultra Awesome X Edition"); |
| 8538 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8539 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8542 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8543 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8544 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8545 | "Host: www.example.org:443\r\n" |
| 8546 | "Proxy-Connection: keep-alive\r\n" |
| 8547 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8548 | }; |
| 8549 | MockRead data_reads[] = { |
| 8550 | // Return an error, so the transaction stops here (this test isn't |
| 8551 | // interested in the rest). |
| 8552 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8553 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8554 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8555 | }; |
| 8556 | |
| 8557 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8558 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8559 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8561 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8562 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8565 | |
| 8566 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8567 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8568 | } |
| 8569 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8570 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8571 | HttpRequestInfo request; |
| 8572 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8573 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8574 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8575 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8578 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8579 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8580 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8581 | MockWrite( |
| 8582 | "GET / HTTP/1.1\r\n" |
| 8583 | "Host: www.example.org\r\n" |
| 8584 | "Connection: keep-alive\r\n" |
| 8585 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8586 | }; |
| 8587 | |
| 8588 | // Lastly, the server responds with the actual content. |
| 8589 | MockRead data_reads[] = { |
| 8590 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8591 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8592 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8593 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8594 | }; |
| 8595 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8596 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8597 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8600 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8601 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8604 | |
| 8605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8607 | } |
| 8608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8609 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8610 | HttpRequestInfo request; |
| 8611 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8612 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8616 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8617 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8618 | MockWrite( |
| 8619 | "POST / HTTP/1.1\r\n" |
| 8620 | "Host: www.example.org\r\n" |
| 8621 | "Connection: keep-alive\r\n" |
| 8622 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | }; |
| 8624 | |
| 8625 | // Lastly, the server responds with the actual content. |
| 8626 | MockRead data_reads[] = { |
| 8627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8629 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8630 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8631 | }; |
| 8632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8634 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8637 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8638 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8641 | |
| 8642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8644 | } |
| 8645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8646 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8647 | HttpRequestInfo request; |
| 8648 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8649 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8650 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8653 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8654 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8655 | MockWrite( |
| 8656 | "PUT / HTTP/1.1\r\n" |
| 8657 | "Host: www.example.org\r\n" |
| 8658 | "Connection: keep-alive\r\n" |
| 8659 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8660 | }; |
| 8661 | |
| 8662 | // Lastly, the server responds with the actual content. |
| 8663 | MockRead data_reads[] = { |
| 8664 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8665 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8666 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8667 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8668 | }; |
| 8669 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8670 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8671 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8672 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8673 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8674 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8675 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8676 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8678 | |
| 8679 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8680 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8681 | } |
| 8682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8683 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8684 | HttpRequestInfo request; |
| 8685 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8686 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8690 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8691 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8692 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8693 | "Host: www.example.org\r\n" |
| 8694 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8695 | }; |
| 8696 | |
| 8697 | // Lastly, the server responds with the actual content. |
| 8698 | MockRead data_reads[] = { |
| 8699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8703 | }; |
| 8704 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8705 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8706 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8707 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8709 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8710 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8711 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8713 | |
| 8714 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8715 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8716 | } |
| 8717 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8718 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8719 | HttpRequestInfo request; |
| 8720 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8721 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8722 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8723 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8725 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8726 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8727 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8728 | MockWrite( |
| 8729 | "GET / HTTP/1.1\r\n" |
| 8730 | "Host: www.example.org\r\n" |
| 8731 | "Connection: keep-alive\r\n" |
| 8732 | "Pragma: no-cache\r\n" |
| 8733 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8734 | }; |
| 8735 | |
| 8736 | // Lastly, the server responds with the actual content. |
| 8737 | MockRead data_reads[] = { |
| 8738 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8739 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8740 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8741 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8742 | }; |
| 8743 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8744 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8745 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8748 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8749 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8750 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8752 | |
| 8753 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8755 | } |
| 8756 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8757 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8758 | HttpRequestInfo request; |
| 8759 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8760 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8761 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8765 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8766 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8767 | MockWrite( |
| 8768 | "GET / HTTP/1.1\r\n" |
| 8769 | "Host: www.example.org\r\n" |
| 8770 | "Connection: keep-alive\r\n" |
| 8771 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8772 | }; |
| 8773 | |
| 8774 | // Lastly, the server responds with the actual content. |
| 8775 | MockRead data_reads[] = { |
| 8776 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8777 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8778 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8779 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8780 | }; |
| 8781 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8782 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8783 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8786 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8787 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8788 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | |
| 8791 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8792 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8793 | } |
| 8794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8795 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8796 | HttpRequestInfo request; |
| 8797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8798 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8799 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8800 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8803 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8804 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8805 | MockWrite( |
| 8806 | "GET / HTTP/1.1\r\n" |
| 8807 | "Host: www.example.org\r\n" |
| 8808 | "Connection: keep-alive\r\n" |
| 8809 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8810 | }; |
| 8811 | |
| 8812 | // Lastly, the server responds with the actual content. |
| 8813 | MockRead data_reads[] = { |
| 8814 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8815 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8816 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8817 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8818 | }; |
| 8819 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8820 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8821 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8822 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8824 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8825 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8826 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8828 | |
| 8829 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8831 | } |
| 8832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8833 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8834 | HttpRequestInfo request; |
| 8835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8836 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8837 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8838 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8839 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8840 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8841 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8842 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8843 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8844 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8845 | MockWrite( |
| 8846 | "GET / HTTP/1.1\r\n" |
| 8847 | "Host: www.example.org\r\n" |
| 8848 | "Connection: keep-alive\r\n" |
| 8849 | "referer: www.foo.com\r\n" |
| 8850 | "hEllo: Kitty\r\n" |
| 8851 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8852 | }; |
| 8853 | |
| 8854 | // Lastly, the server responds with the actual content. |
| 8855 | MockRead data_reads[] = { |
| 8856 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8857 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8858 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8859 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8860 | }; |
| 8861 | |
| 8862 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8863 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8866 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8867 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8868 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8870 | |
| 8871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8873 | } |
| 8874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8875 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8876 | HttpRequestInfo request; |
| 8877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8878 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8879 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8880 | session_deps_.proxy_service = |
| 8881 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8882 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8883 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8884 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8887 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8888 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8889 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8890 | |
| 8891 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8892 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8893 | MockWrite( |
| 8894 | "GET / HTTP/1.1\r\n" |
| 8895 | "Host: www.example.org\r\n" |
| 8896 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8897 | |
| 8898 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8899 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8900 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8901 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8902 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8903 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8904 | }; |
| 8905 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8906 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8907 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8910 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8911 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8912 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8914 | |
| 8915 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8916 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8918 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8919 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8920 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8921 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8922 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8923 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8924 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8925 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8926 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8927 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8928 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8930 | EXPECT_EQ("Payload", response_text); |
| 8931 | } |
| 8932 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8933 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8934 | HttpRequestInfo request; |
| 8935 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8936 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8937 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8938 | session_deps_.proxy_service = |
| 8939 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8940 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8941 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8942 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8945 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8946 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8947 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8948 | |
| 8949 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8950 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8951 | arraysize(write_buffer)), |
| 8952 | MockWrite( |
| 8953 | "GET / HTTP/1.1\r\n" |
| 8954 | "Host: www.example.org\r\n" |
| 8955 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8956 | |
| 8957 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8958 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8959 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8960 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8961 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8962 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8963 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8964 | }; |
| 8965 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8966 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8967 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8968 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8969 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8970 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8971 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8973 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8974 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8975 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8977 | |
| 8978 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8979 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8980 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8981 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8982 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8983 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8984 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8986 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8987 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8988 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8989 | |
| 8990 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8991 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8992 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8993 | EXPECT_EQ("Payload", response_text); |
| 8994 | } |
| 8995 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8996 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8997 | HttpRequestInfo request; |
| 8998 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8999 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9000 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9001 | session_deps_.proxy_service = |
| 9002 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9003 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9004 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9005 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9007 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9008 | |
| 9009 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9010 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9011 | |
| 9012 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9013 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9014 | MockWrite( |
| 9015 | "GET / HTTP/1.1\r\n" |
| 9016 | "Host: www.example.org\r\n" |
| 9017 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9018 | |
| 9019 | MockRead data_reads[] = { |
| 9020 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9021 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9022 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9023 | MockRead("Payload"), |
| 9024 | MockRead(SYNCHRONOUS, OK) |
| 9025 | }; |
| 9026 | |
| 9027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9028 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9030 | |
| 9031 | TestCompletionCallback callback; |
| 9032 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9033 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9035 | |
| 9036 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9037 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9039 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9040 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9041 | |
| 9042 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9043 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9044 | TestLoadTimingNotReused(load_timing_info, |
| 9045 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9046 | |
| 9047 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9048 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9049 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9050 | EXPECT_EQ("Payload", response_text); |
| 9051 | } |
| 9052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9053 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9054 | HttpRequestInfo request; |
| 9055 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9056 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9057 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9058 | session_deps_.proxy_service = |
| 9059 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9060 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9061 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9062 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9064 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9065 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9066 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9067 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9068 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9069 | 0x05, // Version |
| 9070 | 0x01, // Command (CONNECT) |
| 9071 | 0x00, // Reserved. |
| 9072 | 0x03, // Address type (DOMAINNAME). |
| 9073 | 0x0F, // Length of domain (15) |
| 9074 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9075 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9076 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9077 | const char kSOCKS5OkResponse[] = |
| 9078 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9079 | |
| 9080 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9081 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9082 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9083 | MockWrite( |
| 9084 | "GET / HTTP/1.1\r\n" |
| 9085 | "Host: www.example.org\r\n" |
| 9086 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9087 | |
| 9088 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9089 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9090 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9091 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9092 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9093 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9094 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9095 | }; |
| 9096 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9097 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9098 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9099 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9101 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9102 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9103 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9105 | |
| 9106 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9107 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9109 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9110 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9111 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9112 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9113 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9114 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9115 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9116 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9117 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9118 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9119 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9121 | EXPECT_EQ("Payload", response_text); |
| 9122 | } |
| 9123 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9124 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9125 | HttpRequestInfo request; |
| 9126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9127 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9128 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9129 | session_deps_.proxy_service = |
| 9130 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9131 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9132 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9136 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9137 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9138 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9139 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9140 | 0x05, // Version |
| 9141 | 0x01, // Command (CONNECT) |
| 9142 | 0x00, // Reserved. |
| 9143 | 0x03, // Address type (DOMAINNAME). |
| 9144 | 0x0F, // Length of domain (15) |
| 9145 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9146 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9147 | }; |
| 9148 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9149 | const char kSOCKS5OkResponse[] = |
| 9150 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9151 | |
| 9152 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9153 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9154 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9155 | arraysize(kSOCKS5OkRequest)), |
| 9156 | MockWrite( |
| 9157 | "GET / HTTP/1.1\r\n" |
| 9158 | "Host: www.example.org\r\n" |
| 9159 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9160 | |
| 9161 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9162 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9163 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9164 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9165 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9166 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9167 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9168 | }; |
| 9169 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9170 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9171 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9173 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9174 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9177 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9178 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9179 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9181 | |
| 9182 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9183 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9185 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9186 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9187 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9188 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9189 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9190 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9191 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9192 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9193 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9194 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9195 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9196 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9197 | EXPECT_EQ("Payload", response_text); |
| 9198 | } |
| 9199 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9200 | namespace { |
| 9201 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9202 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9203 | |
| 9204 | struct GroupNameTest { |
| 9205 | std::string proxy_server; |
| 9206 | std::string url; |
| 9207 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9208 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9209 | }; |
| 9210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9211 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9212 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9214 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9215 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9216 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9217 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9218 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9219 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9220 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9221 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9222 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9223 | |
| 9224 | return session; |
| 9225 | } |
| 9226 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9227 | int GroupNameTransactionHelper(const std::string& url, |
| 9228 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9229 | HttpRequestInfo request; |
| 9230 | request.method = "GET"; |
| 9231 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9235 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9236 | |
| 9237 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9238 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9239 | } |
| 9240 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9241 | } // namespace |
| 9242 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9243 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9244 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9245 | { |
| 9246 | "", // unused |
| 9247 | "http://www.example.org/direct", |
| 9248 | "www.example.org:80", |
| 9249 | false, |
| 9250 | }, |
| 9251 | { |
| 9252 | "", // unused |
| 9253 | "http://[2001:1418:13:1::25]/direct", |
| 9254 | "[2001:1418:13:1::25]:80", |
| 9255 | false, |
| 9256 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9257 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9258 | // SSL Tests |
| 9259 | { |
| 9260 | "", // unused |
| 9261 | "https://www.example.org/direct_ssl", |
| 9262 | "ssl/www.example.org:443", |
| 9263 | true, |
| 9264 | }, |
| 9265 | { |
| 9266 | "", // unused |
| 9267 | "https://[2001:1418:13:1::25]/direct", |
| 9268 | "ssl/[2001:1418:13:1::25]:443", |
| 9269 | true, |
| 9270 | }, |
| 9271 | { |
| 9272 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9273 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9274 | "ssl/host.with.alternate:443", |
| 9275 | true, |
| 9276 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9277 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9278 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9279 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9280 | session_deps_.proxy_service = |
| 9281 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9282 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9283 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9284 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9285 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9286 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9287 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9288 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9289 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9290 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9291 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9292 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9293 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9294 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9295 | |
| 9296 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9297 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9298 | if (tests[i].ssl) |
| 9299 | EXPECT_EQ(tests[i].expected_group_name, |
| 9300 | ssl_conn_pool->last_group_name_received()); |
| 9301 | else |
| 9302 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9303 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9304 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9305 | } |
| 9306 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9307 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9308 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9309 | { |
| 9310 | "http_proxy", |
| 9311 | "http://www.example.org/http_proxy_normal", |
| 9312 | "www.example.org:80", |
| 9313 | false, |
| 9314 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9315 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9316 | // SSL Tests |
| 9317 | { |
| 9318 | "http_proxy", |
| 9319 | "https://www.example.org/http_connect_ssl", |
| 9320 | "ssl/www.example.org:443", |
| 9321 | true, |
| 9322 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9323 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9324 | { |
| 9325 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9326 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9327 | "ssl/host.with.alternate:443", |
| 9328 | true, |
| 9329 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9330 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9331 | { |
| 9332 | "http_proxy", |
| 9333 | "ftp://ftp.google.com/http_proxy_normal", |
| 9334 | "ftp/ftp.google.com:21", |
| 9335 | false, |
| 9336 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9337 | }; |
| 9338 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9339 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9340 | session_deps_.proxy_service = |
| 9341 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9342 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9343 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9344 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9345 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9346 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9347 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9348 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9349 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9350 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9351 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9353 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9354 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9355 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9356 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9357 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9358 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9359 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9360 | |
| 9361 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9362 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9363 | if (tests[i].ssl) |
| 9364 | EXPECT_EQ(tests[i].expected_group_name, |
| 9365 | ssl_conn_pool->last_group_name_received()); |
| 9366 | else |
| 9367 | EXPECT_EQ(tests[i].expected_group_name, |
| 9368 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9369 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9370 | } |
| 9371 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9372 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9373 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9374 | { |
| 9375 | "socks4://socks_proxy:1080", |
| 9376 | "http://www.example.org/socks4_direct", |
| 9377 | "socks4/www.example.org:80", |
| 9378 | false, |
| 9379 | }, |
| 9380 | { |
| 9381 | "socks5://socks_proxy:1080", |
| 9382 | "http://www.example.org/socks5_direct", |
| 9383 | "socks5/www.example.org:80", |
| 9384 | false, |
| 9385 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9386 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9387 | // SSL Tests |
| 9388 | { |
| 9389 | "socks4://socks_proxy:1080", |
| 9390 | "https://www.example.org/socks4_ssl", |
| 9391 | "socks4/ssl/www.example.org:443", |
| 9392 | true, |
| 9393 | }, |
| 9394 | { |
| 9395 | "socks5://socks_proxy:1080", |
| 9396 | "https://www.example.org/socks5_ssl", |
| 9397 | "socks5/ssl/www.example.org:443", |
| 9398 | true, |
| 9399 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9400 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9401 | { |
| 9402 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9403 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9404 | "socks4/ssl/host.with.alternate:443", |
| 9405 | true, |
| 9406 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9407 | }; |
| 9408 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9409 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9410 | session_deps_.proxy_service = |
| 9411 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9412 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9413 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9414 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9415 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9416 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9417 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9418 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9419 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9420 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9421 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9422 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9423 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9424 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9425 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9426 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9427 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9428 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9429 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9432 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9433 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9434 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9435 | if (tests[i].ssl) |
| 9436 | EXPECT_EQ(tests[i].expected_group_name, |
| 9437 | ssl_conn_pool->last_group_name_received()); |
| 9438 | else |
| 9439 | EXPECT_EQ(tests[i].expected_group_name, |
| 9440 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9441 | } |
| 9442 | } |
| 9443 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9444 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9445 | HttpRequestInfo request; |
| 9446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9447 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9448 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9449 | session_deps_.proxy_service = |
| 9450 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9451 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9452 | // This simulates failure resolving all hostnames; that means we will fail |
| 9453 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9454 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9459 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9460 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9461 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9463 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9464 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9465 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9466 | } |
| 9467 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9468 | // Base test to make sure that when the load flags for a request specify to |
| 9469 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9470 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9471 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9472 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9473 | HttpRequestInfo request_info; |
| 9474 | request_info.method = "GET"; |
| 9475 | request_info.load_flags = load_flags; |
| 9476 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9477 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9478 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9479 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9483 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9484 | // 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] | 9485 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9486 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9487 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9488 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9489 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9490 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9491 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9495 | |
| 9496 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9497 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9498 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9499 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9500 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9501 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9502 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9503 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9504 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9505 | // 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] | 9506 | // we can tell if the next lookup hit the cache, or the "network". |
| 9507 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9508 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9509 | |
| 9510 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9511 | // 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] | 9512 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9513 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9514 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9515 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9516 | // Run the request. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9517 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9518 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9519 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9520 | |
| 9521 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9522 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9523 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9524 | } |
| 9525 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9526 | // There are multiple load flags that should trigger the host cache bypass. |
| 9527 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9528 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9529 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9530 | } |
| 9531 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9532 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9533 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9534 | } |
| 9535 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9536 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9537 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9538 | } |
| 9539 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9540 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9541 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9542 | HttpRequestInfo request; |
| 9543 | request.method = "GET"; |
| 9544 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9545 | |
| 9546 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9547 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9548 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9549 | StaticSocketDataProvider data(NULL, 0, |
| 9550 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9554 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9556 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9557 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9560 | |
| 9561 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9562 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9563 | |
| 9564 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9565 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9566 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9567 | } |
| 9568 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9569 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9570 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9571 | HttpRequestInfo request; |
| 9572 | request.method = "GET"; |
| 9573 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9574 | |
| 9575 | MockRead data_reads[] = { |
| 9576 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9578 | }; |
| 9579 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9580 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9581 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9584 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9586 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9587 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9588 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9590 | |
| 9591 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9592 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9595 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9596 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9597 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9598 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9599 | |
| 9600 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9601 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9602 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9603 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9604 | |
| 9605 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9606 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9607 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9608 | } |
| 9609 | |
| 9610 | // Make sure that a dropped connection while draining the body for auth |
| 9611 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9612 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9613 | HttpRequestInfo request; |
| 9614 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9615 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9616 | |
| 9617 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9618 | MockWrite( |
| 9619 | "GET / HTTP/1.1\r\n" |
| 9620 | "Host: www.example.org\r\n" |
| 9621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9622 | }; |
| 9623 | |
| 9624 | MockRead data_reads1[] = { |
| 9625 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9628 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9629 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9630 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9631 | }; |
| 9632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9633 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9634 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9635 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9637 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9638 | // be issuing -- the final header line contains the credentials. |
| 9639 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9640 | MockWrite( |
| 9641 | "GET / HTTP/1.1\r\n" |
| 9642 | "Host: www.example.org\r\n" |
| 9643 | "Connection: keep-alive\r\n" |
| 9644 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9645 | }; |
| 9646 | |
| 9647 | // Lastly, the server responds with the actual content. |
| 9648 | MockRead data_reads2[] = { |
| 9649 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9650 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9651 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9652 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9653 | }; |
| 9654 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9655 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9656 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9657 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9660 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9663 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9664 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9666 | |
| 9667 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9670 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9671 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9672 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9673 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9674 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9676 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9678 | |
| 9679 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9680 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9681 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9682 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9683 | ASSERT_TRUE(response); |
| 9684 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9685 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9686 | } |
| 9687 | |
| 9688 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9689 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9690 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9691 | |
| 9692 | HttpRequestInfo request; |
| 9693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9694 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9695 | |
| 9696 | MockRead proxy_reads[] = { |
| 9697 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9698 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9699 | }; |
| 9700 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9701 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9702 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9703 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9707 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9708 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9709 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9710 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9713 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9716 | |
| 9717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9718 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9719 | } |
| 9720 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9721 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9722 | HttpRequestInfo request; |
| 9723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9724 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9727 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9728 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9729 | MockRead data_reads[] = { |
| 9730 | 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] | 9731 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9732 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9733 | |
| 9734 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9735 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9737 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9738 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9739 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9741 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9742 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9745 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9746 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9747 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9748 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9749 | |
| 9750 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9751 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9752 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9753 | } |
| 9754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9755 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9756 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9757 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9758 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9759 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9760 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9762 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9763 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9764 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9765 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9766 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9767 | |
| 9768 | HttpRequestInfo request; |
| 9769 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9770 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9771 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9775 | |
| 9776 | MockRead data_reads[] = { |
| 9777 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9778 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9779 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9780 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9781 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9784 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9785 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9786 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9788 | |
| 9789 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9790 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9792 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9793 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9794 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9795 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9796 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9797 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9798 | } |
| 9799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9800 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9801 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9802 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9803 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9804 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9805 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9806 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9808 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9809 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9810 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9811 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9812 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9813 | |
| 9814 | HttpRequestInfo request; |
| 9815 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9816 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9817 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9818 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9819 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9822 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9823 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9826 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9827 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9828 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9830 | |
| 9831 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9832 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9833 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9834 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9835 | } |
| 9836 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9837 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9838 | class FakeUploadElementReader : public UploadElementReader { |
| 9839 | public: |
| 9840 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9841 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9842 | |
| 9843 | const CompletionCallback& callback() const { return callback_; } |
| 9844 | |
| 9845 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9846 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9847 | callback_ = callback; |
| 9848 | return ERR_IO_PENDING; |
| 9849 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9850 | uint64_t GetContentLength() const override { return 0; } |
| 9851 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9852 | int Read(IOBuffer* buf, |
| 9853 | int buf_length, |
| 9854 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9855 | return ERR_FAILED; |
| 9856 | } |
| 9857 | |
| 9858 | private: |
| 9859 | CompletionCallback callback_; |
| 9860 | }; |
| 9861 | |
| 9862 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9863 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9864 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9865 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9866 | |
| 9867 | HttpRequestInfo request; |
| 9868 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9869 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9870 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9871 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9873 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9874 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9875 | |
| 9876 | StaticSocketDataProvider data; |
| 9877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9878 | |
| 9879 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9880 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9882 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9883 | |
| 9884 | // Transaction is pending on request body initialization. |
| 9885 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9886 | |
| 9887 | // Return Init()'s result after the transaction gets destroyed. |
| 9888 | trans.reset(); |
| 9889 | fake_reader->callback().Run(OK); // Should not crash. |
| 9890 | } |
| 9891 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9892 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9893 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9894 | HttpRequestInfo request; |
| 9895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9896 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9897 | |
| 9898 | // First transaction will request a resource and receive a Basic challenge |
| 9899 | // with realm="first_realm". |
| 9900 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9901 | MockWrite( |
| 9902 | "GET / HTTP/1.1\r\n" |
| 9903 | "Host: www.example.org\r\n" |
| 9904 | "Connection: keep-alive\r\n" |
| 9905 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9906 | }; |
| 9907 | MockRead data_reads1[] = { |
| 9908 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9909 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9910 | "\r\n"), |
| 9911 | }; |
| 9912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9913 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9914 | // for first_realm. The server will reject and provide a challenge with |
| 9915 | // second_realm. |
| 9916 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9917 | MockWrite( |
| 9918 | "GET / HTTP/1.1\r\n" |
| 9919 | "Host: www.example.org\r\n" |
| 9920 | "Connection: keep-alive\r\n" |
| 9921 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9922 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9923 | }; |
| 9924 | MockRead data_reads2[] = { |
| 9925 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9926 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9927 | "\r\n"), |
| 9928 | }; |
| 9929 | |
| 9930 | // This again fails, and goes back to first_realm. Make sure that the |
| 9931 | // entry is removed from cache. |
| 9932 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9933 | MockWrite( |
| 9934 | "GET / HTTP/1.1\r\n" |
| 9935 | "Host: www.example.org\r\n" |
| 9936 | "Connection: keep-alive\r\n" |
| 9937 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9938 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9939 | }; |
| 9940 | MockRead data_reads3[] = { |
| 9941 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9942 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9943 | "\r\n"), |
| 9944 | }; |
| 9945 | |
| 9946 | // Try one last time (with the correct password) and get the resource. |
| 9947 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9948 | MockWrite( |
| 9949 | "GET / HTTP/1.1\r\n" |
| 9950 | "Host: www.example.org\r\n" |
| 9951 | "Connection: keep-alive\r\n" |
| 9952 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9953 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9954 | }; |
| 9955 | MockRead data_reads4[] = { |
| 9956 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9957 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9958 | "Content-Length: 5\r\n" |
| 9959 | "\r\n" |
| 9960 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9961 | }; |
| 9962 | |
| 9963 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9964 | data_writes1, arraysize(data_writes1)); |
| 9965 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9966 | data_writes2, arraysize(data_writes2)); |
| 9967 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9968 | data_writes3, arraysize(data_writes3)); |
| 9969 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9970 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9971 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9972 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9973 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9974 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9975 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9976 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9980 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9981 | // Issue the first request with Authorize headers. There should be a |
| 9982 | // password prompt for first_realm waiting to be filled in after the |
| 9983 | // transaction completes. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9984 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9986 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9987 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9988 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9989 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9990 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9991 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9992 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9993 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9994 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9995 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9996 | |
| 9997 | // Issue the second request with an incorrect password. There should be a |
| 9998 | // password prompt for second_realm waiting to be filled in after the |
| 9999 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10000 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10001 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10002 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10004 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10005 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10006 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10007 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10008 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10009 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10010 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10011 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10012 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10013 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10014 | |
| 10015 | // Issue the third request with another incorrect password. There should be |
| 10016 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10017 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10018 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10019 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10020 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10021 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10023 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10024 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10025 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10026 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10027 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10028 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10029 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10030 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10031 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10032 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10033 | |
| 10034 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10035 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10036 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10037 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10039 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10041 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10042 | ASSERT_TRUE(response); |
| 10043 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10044 | } |
| 10045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10046 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10047 | MockRead data_reads[] = { |
| 10048 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10049 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10050 | MockRead("\r\n"), |
| 10051 | MockRead("hello world"), |
| 10052 | MockRead(SYNCHRONOUS, OK), |
| 10053 | }; |
| 10054 | |
| 10055 | HttpRequestInfo request; |
| 10056 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10057 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10058 | |
| 10059 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10061 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10062 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10064 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10065 | TestCompletionCallback callback; |
| 10066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10069 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10070 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10072 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10073 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10074 | HttpServerProperties* http_server_properties = |
| 10075 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10076 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10077 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10078 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10079 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10080 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10082 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10083 | ASSERT_TRUE(response); |
| 10084 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10085 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10086 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10087 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10088 | |
| 10089 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10090 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10091 | EXPECT_EQ("hello world", response_data); |
| 10092 | |
| 10093 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10094 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10095 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10096 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10097 | alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10098 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10099 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10100 | } |
| 10101 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10102 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10103 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10104 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10105 | MockRead data_reads[] = { |
| 10106 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10107 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10108 | MockRead("\r\n"), |
| 10109 | MockRead("hello world"), |
| 10110 | MockRead(SYNCHRONOUS, OK), |
| 10111 | }; |
| 10112 | |
| 10113 | HttpRequestInfo request; |
| 10114 | request.method = "GET"; |
| 10115 | request.url = GURL("http://www.example.org/"); |
| 10116 | request.load_flags = 0; |
| 10117 | |
| 10118 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10119 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10120 | |
| 10121 | TestCompletionCallback callback; |
| 10122 | |
| 10123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10124 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10125 | |
| 10126 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10127 | HttpServerProperties* http_server_properties = |
| 10128 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10129 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10130 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10131 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10132 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10133 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10135 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10137 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10138 | ASSERT_TRUE(response); |
| 10139 | ASSERT_TRUE(response->headers); |
| 10140 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10141 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10142 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10143 | |
| 10144 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10145 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10146 | EXPECT_EQ("hello world", response_data); |
| 10147 | |
| 10148 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10149 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10150 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10151 | } |
| 10152 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10153 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 10154 | // hostname is different from that of origin. |
| 10155 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10156 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10157 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10158 | session_deps_.enable_http2_alternative_service_with_different_host = false; |
| 10159 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10160 | HttpRequestInfo request; |
| 10161 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10162 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10163 | request.load_flags = 0; |
| 10164 | |
| 10165 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10166 | StaticSocketDataProvider first_data; |
| 10167 | first_data.set_connect_data(mock_connect); |
| 10168 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10169 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10170 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10172 | |
| 10173 | MockRead data_reads[] = { |
| 10174 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10175 | MockRead(ASYNC, OK), |
| 10176 | }; |
| 10177 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10178 | 0); |
| 10179 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10180 | |
| 10181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10182 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10183 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10184 | session->http_server_properties(); |
| 10185 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10186 | AlternateProtocolFromNextProto(kProtoHTTP2), "different.example.org", |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10187 | 444); |
| 10188 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10189 | http_server_properties->SetAlternativeService( |
| 10190 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10192 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10193 | TestCompletionCallback callback; |
| 10194 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10195 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10196 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10197 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10198 | } |
| 10199 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10200 | // Regression test for https://crbug.com/615497: |
| 10201 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10202 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10203 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10204 | HttpRequestInfo request; |
| 10205 | request.method = "GET"; |
| 10206 | request.url = GURL("http://www.example.org/"); |
| 10207 | request.load_flags = 0; |
| 10208 | |
| 10209 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10210 | StaticSocketDataProvider first_data; |
| 10211 | first_data.set_connect_data(mock_connect); |
| 10212 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10213 | |
| 10214 | MockRead data_reads[] = { |
| 10215 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10216 | MockRead(ASYNC, OK), |
| 10217 | }; |
| 10218 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10219 | 0); |
| 10220 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10221 | |
| 10222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10223 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10224 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10225 | session->http_server_properties(); |
| 10226 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10227 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10228 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10229 | http_server_properties->SetAlternativeService( |
| 10230 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10233 | TestCompletionCallback callback; |
| 10234 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10235 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10236 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10237 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10238 | } |
| 10239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10240 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10241 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10243 | HttpServerProperties* http_server_properties = |
| 10244 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10245 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10246 | AlternativeService alternative_service(QUIC, "", 80); |
| 10247 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10248 | http_server_properties->SetAlternativeService( |
| 10249 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10250 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10251 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10252 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10253 | |
| 10254 | // Send a clear header. |
| 10255 | MockRead data_reads[] = { |
| 10256 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10257 | MockRead("Alt-Svc: clear\r\n"), |
| 10258 | MockRead("\r\n"), |
| 10259 | MockRead("hello world"), |
| 10260 | MockRead(SYNCHRONOUS, OK), |
| 10261 | }; |
| 10262 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10263 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10264 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10265 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10267 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10268 | HttpRequestInfo request; |
| 10269 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10270 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10271 | |
| 10272 | TestCompletionCallback callback; |
| 10273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10275 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10276 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10277 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10279 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10280 | ASSERT_TRUE(response); |
| 10281 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10282 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10283 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10284 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10285 | |
| 10286 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10287 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10288 | EXPECT_EQ("hello world", response_data); |
| 10289 | |
| 10290 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10291 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10292 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10293 | } |
| 10294 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10295 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10296 | MockRead data_reads[] = { |
| 10297 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10298 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10299 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10300 | MockRead("hello world"), |
| 10301 | MockRead(SYNCHRONOUS, OK), |
| 10302 | }; |
| 10303 | |
| 10304 | HttpRequestInfo request; |
| 10305 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10306 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10307 | |
| 10308 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10309 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10310 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10311 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10313 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10314 | TestCompletionCallback callback; |
| 10315 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10317 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10318 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10319 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10320 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10321 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10322 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10323 | HttpServerProperties* http_server_properties = |
| 10324 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10325 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10326 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10327 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10328 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10329 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10332 | ASSERT_TRUE(response); |
| 10333 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10334 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10335 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10336 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10337 | |
| 10338 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10339 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10340 | EXPECT_EQ("hello world", response_data); |
| 10341 | |
| 10342 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10343 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10344 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10345 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10346 | alternative_service_vector[0].protocol); |
| 10347 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10348 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10349 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 10350 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10351 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10352 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10353 | } |
| 10354 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10355 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10356 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10357 | HostPortPair alternative("alternative.example.org", 443); |
| 10358 | std::string origin_url = "https://origin.example.org:443"; |
| 10359 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10360 | |
| 10361 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10362 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10363 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10365 | |
| 10366 | // HTTP/1.1 data for request. |
| 10367 | MockWrite http_writes[] = { |
| 10368 | MockWrite("GET / HTTP/1.1\r\n" |
| 10369 | "Host: alternative.example.org\r\n" |
| 10370 | "Connection: keep-alive\r\n\r\n"), |
| 10371 | }; |
| 10372 | |
| 10373 | MockRead http_reads[] = { |
| 10374 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10375 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10376 | "Content-Length: 40\r\n\r\n" |
| 10377 | "first HTTP/1.1 response from alternative"), |
| 10378 | }; |
| 10379 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10380 | http_writes, arraysize(http_writes)); |
| 10381 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10382 | |
| 10383 | StaticSocketDataProvider data_refused; |
| 10384 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10385 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10386 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10387 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10389 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10390 | session->http_server_properties(); |
| 10391 | AlternativeService alternative_service(QUIC, alternative); |
| 10392 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10393 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10394 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10395 | // Mark the QUIC alternative service as broken. |
| 10396 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10398 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10399 | HttpRequestInfo request; |
| 10400 | request.method = "GET"; |
| 10401 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10402 | TestCompletionCallback callback; |
| 10403 | NetErrorDetails details; |
| 10404 | EXPECT_FALSE(details.quic_broken); |
| 10405 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10406 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10407 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10408 | EXPECT_TRUE(details.quic_broken); |
| 10409 | } |
| 10410 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10411 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10412 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10413 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10414 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10415 | std::string origin_url = "https://origin.example.org:443"; |
| 10416 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10417 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10418 | |
| 10419 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10420 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10421 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10423 | |
| 10424 | // HTTP/1.1 data for request. |
| 10425 | MockWrite http_writes[] = { |
| 10426 | MockWrite("GET / HTTP/1.1\r\n" |
| 10427 | "Host: alternative1.example.org\r\n" |
| 10428 | "Connection: keep-alive\r\n\r\n"), |
| 10429 | }; |
| 10430 | |
| 10431 | MockRead http_reads[] = { |
| 10432 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10433 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10434 | "Content-Length: 40\r\n\r\n" |
| 10435 | "first HTTP/1.1 response from alternative1"), |
| 10436 | }; |
| 10437 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10438 | http_writes, arraysize(http_writes)); |
| 10439 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10440 | |
| 10441 | StaticSocketDataProvider data_refused; |
| 10442 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10443 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10444 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10446 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10447 | session->http_server_properties(); |
| 10448 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10449 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10450 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10451 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10452 | |
| 10453 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10454 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10455 | expiration); |
| 10456 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10457 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10458 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10459 | expiration); |
| 10460 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10461 | |
| 10462 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10463 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10464 | |
| 10465 | // Mark one of the QUIC alternative service as broken. |
| 10466 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10467 | |
| 10468 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10469 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10472 | HttpRequestInfo request; |
| 10473 | request.method = "GET"; |
| 10474 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10475 | TestCompletionCallback callback; |
| 10476 | NetErrorDetails details; |
| 10477 | EXPECT_FALSE(details.quic_broken); |
| 10478 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10479 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10480 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10481 | EXPECT_FALSE(details.quic_broken); |
| 10482 | } |
| 10483 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10484 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10485 | HttpRequestInfo request; |
| 10486 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10487 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10488 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10489 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10490 | StaticSocketDataProvider first_data; |
| 10491 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10493 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10494 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10496 | |
| 10497 | MockRead data_reads[] = { |
| 10498 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10499 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10500 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10501 | }; |
| 10502 | StaticSocketDataProvider second_data( |
| 10503 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10504 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10505 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10507 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10508 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10509 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10510 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10511 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10512 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10513 | const AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10514 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10515 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10516 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10517 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10518 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10520 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10521 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10522 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10523 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10524 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10525 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10527 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10528 | ASSERT_TRUE(response); |
| 10529 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10530 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10531 | |
| 10532 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10533 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10534 | EXPECT_EQ("hello world", response_data); |
| 10535 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10536 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10537 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10538 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10539 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10540 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10541 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10542 | } |
| 10543 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10544 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10545 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10546 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10547 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10548 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10549 | HttpRequestInfo restricted_port_request; |
| 10550 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10551 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10552 | restricted_port_request.load_flags = 0; |
| 10553 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10554 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10555 | StaticSocketDataProvider first_data; |
| 10556 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10557 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10558 | |
| 10559 | MockRead data_reads[] = { |
| 10560 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10561 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10562 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10563 | }; |
| 10564 | StaticSocketDataProvider second_data( |
| 10565 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10566 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10567 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10568 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10570 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10572 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10573 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10574 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10575 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10576 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10577 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10578 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10579 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10580 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10581 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10582 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10583 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10585 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10586 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10587 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10588 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10590 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10591 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10592 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10593 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10594 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10595 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10596 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10597 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10598 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10599 | |
| 10600 | HttpRequestInfo restricted_port_request; |
| 10601 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10602 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10603 | restricted_port_request.load_flags = 0; |
| 10604 | |
| 10605 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10606 | StaticSocketDataProvider first_data; |
| 10607 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10608 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10609 | |
| 10610 | MockRead data_reads[] = { |
| 10611 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10612 | MockRead("hello world"), |
| 10613 | MockRead(ASYNC, OK), |
| 10614 | }; |
| 10615 | StaticSocketDataProvider second_data( |
| 10616 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10617 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10618 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10619 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10621 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10623 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10624 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10625 | session->http_server_properties(); |
| 10626 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10627 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10628 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10629 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10630 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10631 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10632 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10633 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10636 | TestCompletionCallback callback; |
| 10637 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10638 | EXPECT_EQ(ERR_IO_PENDING, |
| 10639 | trans.Start(&restricted_port_request, callback.callback(), |
| 10640 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10641 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10642 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10643 | } |
| 10644 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10645 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10646 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10647 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10648 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10649 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10650 | HttpRequestInfo restricted_port_request; |
| 10651 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10652 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10653 | restricted_port_request.load_flags = 0; |
| 10654 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10655 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10656 | StaticSocketDataProvider first_data; |
| 10657 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10658 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10659 | |
| 10660 | MockRead data_reads[] = { |
| 10661 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10662 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10663 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10664 | }; |
| 10665 | StaticSocketDataProvider second_data( |
| 10666 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10667 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10668 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10669 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10670 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10673 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10674 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10675 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10676 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10677 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10678 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10679 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10680 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10681 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10682 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10683 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10686 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10687 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10688 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10689 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10691 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10692 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10693 | } |
| 10694 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10695 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10696 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10697 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10698 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10699 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10700 | HttpRequestInfo unrestricted_port_request; |
| 10701 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10702 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10703 | unrestricted_port_request.load_flags = 0; |
| 10704 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10705 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10706 | StaticSocketDataProvider first_data; |
| 10707 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10708 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10709 | |
| 10710 | MockRead data_reads[] = { |
| 10711 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10712 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10713 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10714 | }; |
| 10715 | StaticSocketDataProvider second_data( |
| 10716 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10717 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10718 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10719 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10721 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10722 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10723 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10724 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10725 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10726 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10727 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10728 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10729 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10730 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10731 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10732 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10733 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10736 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10738 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10739 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10741 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10742 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10743 | } |
| 10744 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10745 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10746 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10747 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10748 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10749 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10750 | HttpRequestInfo unrestricted_port_request; |
| 10751 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10752 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | unrestricted_port_request.load_flags = 0; |
| 10754 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10755 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10756 | StaticSocketDataProvider first_data; |
| 10757 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10758 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10759 | |
| 10760 | MockRead data_reads[] = { |
| 10761 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10762 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10763 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10764 | }; |
| 10765 | StaticSocketDataProvider second_data( |
| 10766 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10767 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10768 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10769 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10773 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10774 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10775 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10776 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10777 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10778 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10779 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10780 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10781 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10782 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10783 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10784 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10786 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10788 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10789 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10791 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10792 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10793 | } |
| 10794 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10795 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10796 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10797 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10798 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10799 | HttpRequestInfo request; |
| 10800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10801 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10802 | |
| 10803 | // The alternate protocol request will error out before we attempt to connect, |
| 10804 | // so only the standard HTTP request will try to connect. |
| 10805 | MockRead data_reads[] = { |
| 10806 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10807 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10808 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10809 | }; |
| 10810 | StaticSocketDataProvider data( |
| 10811 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10812 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10815 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10816 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10817 | session->http_server_properties(); |
| 10818 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10819 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10820 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10821 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10822 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10823 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10824 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10826 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10827 | TestCompletionCallback callback; |
| 10828 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10829 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10831 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10834 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10835 | ASSERT_TRUE(response); |
| 10836 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10837 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10838 | |
| 10839 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10840 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10841 | EXPECT_EQ("hello world", response_data); |
| 10842 | } |
| 10843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10844 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10845 | HttpRequestInfo request; |
| 10846 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10847 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10848 | |
| 10849 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10850 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10851 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10852 | MockRead("\r\n"), |
| 10853 | MockRead("hello world"), |
| 10854 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10855 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10856 | |
| 10857 | StaticSocketDataProvider first_transaction( |
| 10858 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10860 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10861 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10863 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10864 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10865 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10866 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10867 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10868 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10869 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10870 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10871 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10872 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10873 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10874 | }; |
| 10875 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10876 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10877 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10879 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10880 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10881 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10882 | NULL, 0, NULL, 0); |
| 10883 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10884 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10885 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10886 | &hanging_non_alternate_protocol_socket); |
| 10887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10888 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10889 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10893 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10894 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10896 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10897 | |
| 10898 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10899 | ASSERT_TRUE(response); |
| 10900 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10901 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10902 | |
| 10903 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10904 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10905 | EXPECT_EQ("hello world", response_data); |
| 10906 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10907 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10908 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10909 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10911 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10912 | |
| 10913 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10914 | ASSERT_TRUE(response); |
| 10915 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10916 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10917 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10918 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10919 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10921 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10922 | } |
| 10923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10924 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10925 | HttpRequestInfo request; |
| 10926 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10927 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10928 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10929 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10931 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10932 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10933 | MockRead("\r\n"), |
| 10934 | MockRead("hello world"), |
| 10935 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10936 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10937 | }; |
| 10938 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10939 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10940 | 0); |
| 10941 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10942 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10943 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10945 | |
| 10946 | // Second transaction starts an alternative and a non-alternative Job. |
| 10947 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10948 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10949 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10950 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10951 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10952 | |
| 10953 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10954 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10955 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10956 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10957 | // Third transaction starts an alternative and a non-alternative job. |
| 10958 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10959 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10960 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10961 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10962 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10963 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10964 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10965 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10966 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10967 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10968 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10969 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10970 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10971 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10972 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10973 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10974 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10975 | }; |
| 10976 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10977 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10978 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10979 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10980 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10981 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10983 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10984 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10985 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10988 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10989 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10990 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10991 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10993 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10994 | |
| 10995 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10996 | ASSERT_TRUE(response); |
| 10997 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10998 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10999 | |
| 11000 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11001 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11002 | EXPECT_EQ("hello world", response_data); |
| 11003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11004 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11005 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11006 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11008 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11009 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11010 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11011 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11013 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11014 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11015 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11016 | |
| 11017 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11018 | ASSERT_TRUE(response); |
| 11019 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11020 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11021 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11022 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11023 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11024 | EXPECT_EQ("hello!", response_data); |
| 11025 | |
| 11026 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11027 | ASSERT_TRUE(response); |
| 11028 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11029 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11030 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11031 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11032 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11033 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11034 | } |
| 11035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11036 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11037 | HttpRequestInfo request; |
| 11038 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11039 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11040 | |
| 11041 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11042 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11043 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11044 | MockRead("\r\n"), |
| 11045 | MockRead("hello world"), |
| 11046 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11047 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11048 | }; |
| 11049 | |
| 11050 | StaticSocketDataProvider first_transaction( |
| 11051 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11052 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11053 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11054 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11056 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11057 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11058 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11059 | NULL, 0, NULL, 0); |
| 11060 | hanging_alternate_protocol_socket.set_connect_data( |
| 11061 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11062 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11063 | &hanging_alternate_protocol_socket); |
| 11064 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11065 | // 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] | 11066 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11067 | NULL, 0); |
| 11068 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11071 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 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 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11075 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11076 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11077 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11078 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11079 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11080 | |
| 11081 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11082 | ASSERT_TRUE(response); |
| 11083 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11084 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11085 | |
| 11086 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11087 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11088 | EXPECT_EQ("hello world", response_data); |
| 11089 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11090 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11091 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11092 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11094 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11095 | |
| 11096 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11097 | ASSERT_TRUE(response); |
| 11098 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11099 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11100 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11101 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11103 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11104 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11105 | } |
| 11106 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11107 | class CapturingProxyResolver : public ProxyResolver { |
| 11108 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11109 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11110 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11111 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11112 | int GetProxyForURL(const GURL& url, |
| 11113 | ProxyInfo* results, |
| 11114 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11115 | std::unique_ptr<Request>* request, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11116 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11117 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11118 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11119 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11120 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11121 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11122 | } |
| 11123 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11124 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11125 | |
| 11126 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11127 | std::vector<GURL> resolved_; |
| 11128 | |
| 11129 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11130 | }; |
| 11131 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11132 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11133 | public: |
| 11134 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11135 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11136 | |
| 11137 | int CreateProxyResolver( |
| 11138 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11139 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11140 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11141 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11142 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11143 | return OK; |
| 11144 | } |
| 11145 | |
| 11146 | private: |
| 11147 | ProxyResolver* resolver_; |
| 11148 | }; |
| 11149 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11150 | // Test that proxy is resolved using the origin url, |
| 11151 | // regardless of the alternative server. |
| 11152 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11153 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11154 | ProxyConfig proxy_config; |
| 11155 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11156 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11157 | auto proxy_config_service = |
| 11158 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11159 | |
| 11160 | CapturingProxyResolver capturing_proxy_resolver; |
| 11161 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11162 | &capturing_proxy_resolver); |
| 11163 | |
| 11164 | TestNetLog net_log; |
| 11165 | |
| 11166 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11167 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11168 | &net_log); |
| 11169 | |
| 11170 | session_deps_.net_log = &net_log; |
| 11171 | |
| 11172 | // Configure alternative service with a hostname that is not bypassed by the |
| 11173 | // proxy. |
| 11174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11175 | HttpServerProperties* http_server_properties = |
| 11176 | session->http_server_properties(); |
| 11177 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11178 | HostPortPair alternative("www.example.com", 443); |
| 11179 | AlternativeService alternative_service( |
| 11180 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
| 11181 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11182 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11183 | expiration); |
| 11184 | |
| 11185 | // Non-alternative job should hang. |
| 11186 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11187 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11188 | nullptr, 0); |
| 11189 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11190 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11191 | &hanging_alternate_protocol_socket); |
| 11192 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11193 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11194 | |
| 11195 | HttpRequestInfo request; |
| 11196 | request.method = "GET"; |
| 11197 | request.url = GURL("https://www.example.org/"); |
| 11198 | request.load_flags = 0; |
| 11199 | |
| 11200 | SpdySerializedFrame req( |
| 11201 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11202 | |
| 11203 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11204 | |
| 11205 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11206 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11207 | MockRead spdy_reads[] = { |
| 11208 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11209 | }; |
| 11210 | |
| 11211 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11212 | arraysize(spdy_writes)); |
| 11213 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11214 | |
| 11215 | TestCompletionCallback callback; |
| 11216 | |
| 11217 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11218 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11219 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11221 | |
| 11222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11223 | ASSERT_TRUE(response); |
| 11224 | ASSERT_TRUE(response->headers); |
| 11225 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11226 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11227 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11228 | |
| 11229 | std::string response_data; |
| 11230 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11231 | EXPECT_EQ("hello!", response_data); |
| 11232 | |
| 11233 | // Origin host bypasses proxy, no resolution should have happened. |
| 11234 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11235 | } |
| 11236 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11237 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11238 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11239 | proxy_config.set_auto_detect(true); |
| 11240 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11241 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11242 | CapturingProxyResolver capturing_proxy_resolver; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11243 | session_deps_.proxy_service.reset( |
| 11244 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11245 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11246 | &capturing_proxy_resolver), |
| 11247 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11248 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11249 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11250 | |
| 11251 | HttpRequestInfo request; |
| 11252 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11253 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11254 | |
| 11255 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11256 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11257 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11258 | MockRead("\r\n"), |
| 11259 | MockRead("hello world"), |
| 11260 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11261 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11262 | }; |
| 11263 | |
| 11264 | StaticSocketDataProvider first_transaction( |
| 11265 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11266 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11267 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11268 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11270 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11271 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11272 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11273 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11274 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11275 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11276 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11277 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11278 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11279 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11280 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11281 | }; |
| 11282 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11283 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11284 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11285 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11286 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11287 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11288 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11289 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11290 | }; |
| 11291 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11292 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11293 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11294 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11295 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11296 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11297 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11298 | NULL, 0, NULL, 0); |
| 11299 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11300 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11301 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11302 | &hanging_non_alternate_protocol_socket); |
| 11303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11304 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11305 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11306 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11307 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11308 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11309 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11310 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11312 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11313 | |
| 11314 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11315 | ASSERT_TRUE(response); |
| 11316 | ASSERT_TRUE(response->headers); |
| 11317 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11318 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11319 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11320 | |
| 11321 | std::string response_data; |
| 11322 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11323 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11324 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11325 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11326 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11327 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11329 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11330 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11331 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11332 | ASSERT_TRUE(response); |
| 11333 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11334 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11335 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11336 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11337 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11338 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11339 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11340 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11341 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11342 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11343 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11344 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11345 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11346 | LoadTimingInfo load_timing_info; |
| 11347 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11348 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11349 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11350 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11351 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11352 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11353 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11354 | HttpRequestInfo request; |
| 11355 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11356 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11357 | |
| 11358 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11359 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11360 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11361 | MockRead("\r\n"), |
| 11362 | MockRead("hello world"), |
| 11363 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11364 | }; |
| 11365 | |
| 11366 | StaticSocketDataProvider first_transaction( |
| 11367 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11368 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11369 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11370 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11372 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11373 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11374 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11375 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11376 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11377 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11378 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11379 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11380 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11381 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11382 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11383 | }; |
| 11384 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11385 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11386 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11387 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11388 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11389 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11390 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11393 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11394 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11395 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11396 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11398 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11399 | |
| 11400 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11401 | ASSERT_TRUE(response); |
| 11402 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11403 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11404 | |
| 11405 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11406 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11407 | EXPECT_EQ("hello world", response_data); |
| 11408 | |
| 11409 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11410 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11411 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11412 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11413 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11414 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11415 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11416 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11417 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11418 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11420 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11421 | |
| 11422 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11423 | ASSERT_TRUE(response); |
| 11424 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11425 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11426 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11427 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11428 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11429 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11430 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11431 | } |
| 11432 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11433 | // GenerateAuthToken is a mighty big test. |
| 11434 | // It tests all permutation of GenerateAuthToken behavior: |
| 11435 | // - Synchronous and Asynchronous completion. |
| 11436 | // - OK or error on completion. |
| 11437 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11438 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11439 | // - Non-authenticating and authenticating backend. |
| 11440 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11441 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11442 | // problems generating an auth token for an authenticating proxy, we don't |
| 11443 | // need to test all permutations of the backend server). |
| 11444 | // |
| 11445 | // The test proceeds by going over each of the configuration cases, and |
| 11446 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11447 | // specifies both the configuration for the test as well as the expectations |
| 11448 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11449 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11450 | static const char kServer[] = "http://www.example.com"; |
| 11451 | static const char kSecureServer[] = "https://www.example.com"; |
| 11452 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11453 | |
| 11454 | enum AuthTiming { |
| 11455 | AUTH_NONE, |
| 11456 | AUTH_SYNC, |
| 11457 | AUTH_ASYNC, |
| 11458 | }; |
| 11459 | |
| 11460 | const MockWrite kGet( |
| 11461 | "GET / HTTP/1.1\r\n" |
| 11462 | "Host: www.example.com\r\n" |
| 11463 | "Connection: keep-alive\r\n\r\n"); |
| 11464 | const MockWrite kGetProxy( |
| 11465 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11466 | "Host: www.example.com\r\n" |
| 11467 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11468 | const MockWrite kGetAuth( |
| 11469 | "GET / HTTP/1.1\r\n" |
| 11470 | "Host: www.example.com\r\n" |
| 11471 | "Connection: keep-alive\r\n" |
| 11472 | "Authorization: auth_token\r\n\r\n"); |
| 11473 | const MockWrite kGetProxyAuth( |
| 11474 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11475 | "Host: www.example.com\r\n" |
| 11476 | "Proxy-Connection: keep-alive\r\n" |
| 11477 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11478 | const MockWrite kGetAuthThroughProxy( |
| 11479 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11480 | "Host: www.example.com\r\n" |
| 11481 | "Proxy-Connection: keep-alive\r\n" |
| 11482 | "Authorization: auth_token\r\n\r\n"); |
| 11483 | const MockWrite kGetAuthWithProxyAuth( |
| 11484 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11485 | "Host: www.example.com\r\n" |
| 11486 | "Proxy-Connection: keep-alive\r\n" |
| 11487 | "Proxy-Authorization: auth_token\r\n" |
| 11488 | "Authorization: auth_token\r\n\r\n"); |
| 11489 | const MockWrite kConnect( |
| 11490 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11491 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11492 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11493 | const MockWrite kConnectProxyAuth( |
| 11494 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11495 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11496 | "Proxy-Connection: keep-alive\r\n" |
| 11497 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11498 | |
| 11499 | const MockRead kSuccess( |
| 11500 | "HTTP/1.1 200 OK\r\n" |
| 11501 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11502 | "Content-Length: 3\r\n\r\n" |
| 11503 | "Yes"); |
| 11504 | const MockRead kFailure( |
| 11505 | "Should not be called."); |
| 11506 | const MockRead kServerChallenge( |
| 11507 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11508 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11509 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11510 | "Content-Length: 14\r\n\r\n" |
| 11511 | "Unauthorized\r\n"); |
| 11512 | const MockRead kProxyChallenge( |
| 11513 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11514 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11515 | "Proxy-Connection: close\r\n" |
| 11516 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11517 | "Content-Length: 14\r\n\r\n" |
| 11518 | "Unauthorized\r\n"); |
| 11519 | const MockRead kProxyConnected( |
| 11520 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11521 | |
| 11522 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11523 | // no constructors, but the C++ compiler on Windows warns about |
| 11524 | // unspecified data in compound literals. So, moved to using constructors, |
| 11525 | // and TestRound's created with the default constructor should not be used. |
| 11526 | struct TestRound { |
| 11527 | TestRound() |
| 11528 | : expected_rv(ERR_UNEXPECTED), |
| 11529 | extra_write(NULL), |
| 11530 | extra_read(NULL) { |
| 11531 | } |
| 11532 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11533 | int expected_rv_arg) |
| 11534 | : write(write_arg), |
| 11535 | read(read_arg), |
| 11536 | expected_rv(expected_rv_arg), |
| 11537 | extra_write(NULL), |
| 11538 | extra_read(NULL) { |
| 11539 | } |
| 11540 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11541 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11542 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11543 | : write(write_arg), |
| 11544 | read(read_arg), |
| 11545 | expected_rv(expected_rv_arg), |
| 11546 | extra_write(extra_write_arg), |
| 11547 | extra_read(extra_read_arg) { |
| 11548 | } |
| 11549 | MockWrite write; |
| 11550 | MockRead read; |
| 11551 | int expected_rv; |
| 11552 | const MockWrite* extra_write; |
| 11553 | const MockRead* extra_read; |
| 11554 | }; |
| 11555 | |
| 11556 | static const int kNoSSL = 500; |
| 11557 | |
| 11558 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11559 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11560 | AuthTiming proxy_auth_timing; |
| 11561 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11562 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11563 | AuthTiming server_auth_timing; |
| 11564 | int server_auth_rv; |
| 11565 | int num_auth_rounds; |
| 11566 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11567 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11568 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11569 | // Non-authenticating HTTP server with a direct connection. |
| 11570 | {NULL, |
| 11571 | AUTH_NONE, |
| 11572 | OK, |
| 11573 | kServer, |
| 11574 | AUTH_NONE, |
| 11575 | OK, |
| 11576 | 1, |
| 11577 | kNoSSL, |
| 11578 | {TestRound(kGet, kSuccess, OK)}}, |
| 11579 | // Authenticating HTTP server with a direct connection. |
| 11580 | {NULL, |
| 11581 | AUTH_NONE, |
| 11582 | OK, |
| 11583 | kServer, |
| 11584 | AUTH_SYNC, |
| 11585 | OK, |
| 11586 | 2, |
| 11587 | kNoSSL, |
| 11588 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11589 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11590 | {NULL, |
| 11591 | AUTH_NONE, |
| 11592 | OK, |
| 11593 | kServer, |
| 11594 | AUTH_SYNC, |
| 11595 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11596 | 3, |
| 11597 | kNoSSL, |
| 11598 | {TestRound(kGet, kServerChallenge, OK), |
| 11599 | TestRound(kGet, kServerChallenge, OK), |
| 11600 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11601 | {NULL, |
| 11602 | AUTH_NONE, |
| 11603 | OK, |
| 11604 | kServer, |
| 11605 | AUTH_SYNC, |
| 11606 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11607 | 2, |
| 11608 | kNoSSL, |
| 11609 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
| 11610 | {NULL, |
| 11611 | AUTH_NONE, |
| 11612 | OK, |
| 11613 | kServer, |
| 11614 | AUTH_SYNC, |
| 11615 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11616 | 2, |
| 11617 | kNoSSL, |
| 11618 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
| 11619 | {kProxy, |
| 11620 | AUTH_SYNC, |
| 11621 | ERR_FAILED, |
| 11622 | kServer, |
| 11623 | AUTH_NONE, |
| 11624 | OK, |
| 11625 | 2, |
| 11626 | kNoSSL, |
| 11627 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11628 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
| 11629 | {kProxy, |
| 11630 | AUTH_ASYNC, |
| 11631 | ERR_FAILED, |
| 11632 | kServer, |
| 11633 | AUTH_NONE, |
| 11634 | OK, |
| 11635 | 2, |
| 11636 | kNoSSL, |
| 11637 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11638 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
| 11639 | {NULL, |
| 11640 | AUTH_NONE, |
| 11641 | OK, |
| 11642 | kServer, |
| 11643 | AUTH_SYNC, |
| 11644 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11645 | 2, |
| 11646 | kNoSSL, |
| 11647 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11648 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
| 11649 | {NULL, |
| 11650 | AUTH_NONE, |
| 11651 | OK, |
| 11652 | kServer, |
| 11653 | AUTH_ASYNC, |
| 11654 | ERR_FAILED, |
| 11655 | 2, |
| 11656 | kNoSSL, |
| 11657 | {TestRound(kGet, kServerChallenge, OK), |
| 11658 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11659 | {NULL, |
| 11660 | AUTH_NONE, |
| 11661 | OK, |
| 11662 | kServer, |
| 11663 | AUTH_ASYNC, |
| 11664 | OK, |
| 11665 | 2, |
| 11666 | kNoSSL, |
| 11667 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11668 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11669 | {NULL, |
| 11670 | AUTH_NONE, |
| 11671 | OK, |
| 11672 | kServer, |
| 11673 | AUTH_ASYNC, |
| 11674 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11675 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11676 | kNoSSL, |
| 11677 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11678 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11679 | TestRound(kGet, kServerChallenge, OK), |
| 11680 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11681 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11682 | {kProxy, |
| 11683 | AUTH_NONE, |
| 11684 | OK, |
| 11685 | kServer, |
| 11686 | AUTH_NONE, |
| 11687 | OK, |
| 11688 | 1, |
| 11689 | kNoSSL, |
| 11690 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11691 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11692 | {kProxy, |
| 11693 | AUTH_NONE, |
| 11694 | OK, |
| 11695 | kServer, |
| 11696 | AUTH_SYNC, |
| 11697 | OK, |
| 11698 | 2, |
| 11699 | kNoSSL, |
| 11700 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11701 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11702 | {kProxy, |
| 11703 | AUTH_NONE, |
| 11704 | OK, |
| 11705 | kServer, |
| 11706 | AUTH_SYNC, |
| 11707 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11708 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11709 | kNoSSL, |
| 11710 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11711 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11712 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11713 | {kProxy, |
| 11714 | AUTH_NONE, |
| 11715 | OK, |
| 11716 | kServer, |
| 11717 | AUTH_ASYNC, |
| 11718 | OK, |
| 11719 | 2, |
| 11720 | kNoSSL, |
| 11721 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11722 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11723 | {kProxy, |
| 11724 | AUTH_NONE, |
| 11725 | OK, |
| 11726 | kServer, |
| 11727 | AUTH_ASYNC, |
| 11728 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11729 | 2, |
| 11730 | kNoSSL, |
| 11731 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11732 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11733 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11734 | {kProxy, |
| 11735 | AUTH_SYNC, |
| 11736 | OK, |
| 11737 | kServer, |
| 11738 | AUTH_NONE, |
| 11739 | OK, |
| 11740 | 2, |
| 11741 | kNoSSL, |
| 11742 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11743 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11744 | {kProxy, |
| 11745 | AUTH_SYNC, |
| 11746 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11747 | kServer, |
| 11748 | AUTH_NONE, |
| 11749 | OK, |
| 11750 | 2, |
| 11751 | kNoSSL, |
| 11752 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11753 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11754 | {kProxy, |
| 11755 | AUTH_ASYNC, |
| 11756 | OK, |
| 11757 | kServer, |
| 11758 | AUTH_NONE, |
| 11759 | OK, |
| 11760 | 2, |
| 11761 | kNoSSL, |
| 11762 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11763 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11764 | {kProxy, |
| 11765 | AUTH_ASYNC, |
| 11766 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11767 | kServer, |
| 11768 | AUTH_NONE, |
| 11769 | OK, |
| 11770 | 2, |
| 11771 | kNoSSL, |
| 11772 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11773 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11774 | // Authenticating HTTP server through an authenticating proxy. |
| 11775 | {kProxy, |
| 11776 | AUTH_SYNC, |
| 11777 | OK, |
| 11778 | kServer, |
| 11779 | AUTH_SYNC, |
| 11780 | OK, |
| 11781 | 3, |
| 11782 | kNoSSL, |
| 11783 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11784 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11785 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11786 | {kProxy, |
| 11787 | AUTH_SYNC, |
| 11788 | OK, |
| 11789 | kServer, |
| 11790 | AUTH_SYNC, |
| 11791 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11792 | 3, |
| 11793 | kNoSSL, |
| 11794 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11795 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11796 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11797 | {kProxy, |
| 11798 | AUTH_ASYNC, |
| 11799 | OK, |
| 11800 | kServer, |
| 11801 | AUTH_SYNC, |
| 11802 | OK, |
| 11803 | 3, |
| 11804 | kNoSSL, |
| 11805 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11806 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11807 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11808 | {kProxy, |
| 11809 | AUTH_ASYNC, |
| 11810 | OK, |
| 11811 | kServer, |
| 11812 | AUTH_SYNC, |
| 11813 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11814 | 3, |
| 11815 | kNoSSL, |
| 11816 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11817 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11818 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11819 | {kProxy, |
| 11820 | AUTH_SYNC, |
| 11821 | OK, |
| 11822 | kServer, |
| 11823 | AUTH_ASYNC, |
| 11824 | OK, |
| 11825 | 3, |
| 11826 | kNoSSL, |
| 11827 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11828 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11829 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11830 | {kProxy, |
| 11831 | AUTH_SYNC, |
| 11832 | OK, |
| 11833 | kServer, |
| 11834 | AUTH_ASYNC, |
| 11835 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11836 | 3, |
| 11837 | kNoSSL, |
| 11838 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11839 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11840 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11841 | {kProxy, |
| 11842 | AUTH_ASYNC, |
| 11843 | OK, |
| 11844 | kServer, |
| 11845 | AUTH_ASYNC, |
| 11846 | OK, |
| 11847 | 3, |
| 11848 | kNoSSL, |
| 11849 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11850 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11851 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11852 | {kProxy, |
| 11853 | AUTH_ASYNC, |
| 11854 | OK, |
| 11855 | kServer, |
| 11856 | AUTH_ASYNC, |
| 11857 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11858 | 3, |
| 11859 | kNoSSL, |
| 11860 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11861 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11862 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11863 | // Non-authenticating HTTPS server with a direct connection. |
| 11864 | {NULL, |
| 11865 | AUTH_NONE, |
| 11866 | OK, |
| 11867 | kSecureServer, |
| 11868 | AUTH_NONE, |
| 11869 | OK, |
| 11870 | 1, |
| 11871 | 0, |
| 11872 | {TestRound(kGet, kSuccess, OK)}}, |
| 11873 | // Authenticating HTTPS server with a direct connection. |
| 11874 | {NULL, |
| 11875 | AUTH_NONE, |
| 11876 | OK, |
| 11877 | kSecureServer, |
| 11878 | AUTH_SYNC, |
| 11879 | OK, |
| 11880 | 2, |
| 11881 | 0, |
| 11882 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11883 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11884 | {NULL, |
| 11885 | AUTH_NONE, |
| 11886 | OK, |
| 11887 | kSecureServer, |
| 11888 | AUTH_SYNC, |
| 11889 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11890 | 2, |
| 11891 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11892 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11893 | {NULL, |
| 11894 | AUTH_NONE, |
| 11895 | OK, |
| 11896 | kSecureServer, |
| 11897 | AUTH_ASYNC, |
| 11898 | OK, |
| 11899 | 2, |
| 11900 | 0, |
| 11901 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11902 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11903 | {NULL, |
| 11904 | AUTH_NONE, |
| 11905 | OK, |
| 11906 | kSecureServer, |
| 11907 | AUTH_ASYNC, |
| 11908 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11909 | 2, |
| 11910 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11911 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11912 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11913 | {kProxy, |
| 11914 | AUTH_NONE, |
| 11915 | OK, |
| 11916 | kSecureServer, |
| 11917 | AUTH_NONE, |
| 11918 | OK, |
| 11919 | 1, |
| 11920 | 0, |
| 11921 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11922 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11923 | {kProxy, |
| 11924 | AUTH_NONE, |
| 11925 | OK, |
| 11926 | kSecureServer, |
| 11927 | AUTH_SYNC, |
| 11928 | OK, |
| 11929 | 2, |
| 11930 | 0, |
| 11931 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11932 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11933 | {kProxy, |
| 11934 | AUTH_NONE, |
| 11935 | OK, |
| 11936 | kSecureServer, |
| 11937 | AUTH_SYNC, |
| 11938 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11939 | 2, |
| 11940 | 0, |
| 11941 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11942 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11943 | {kProxy, |
| 11944 | AUTH_NONE, |
| 11945 | OK, |
| 11946 | kSecureServer, |
| 11947 | AUTH_ASYNC, |
| 11948 | OK, |
| 11949 | 2, |
| 11950 | 0, |
| 11951 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11952 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11953 | {kProxy, |
| 11954 | AUTH_NONE, |
| 11955 | OK, |
| 11956 | kSecureServer, |
| 11957 | AUTH_ASYNC, |
| 11958 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11959 | 2, |
| 11960 | 0, |
| 11961 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11962 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11963 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11964 | {kProxy, |
| 11965 | AUTH_SYNC, |
| 11966 | OK, |
| 11967 | kSecureServer, |
| 11968 | AUTH_NONE, |
| 11969 | OK, |
| 11970 | 2, |
| 11971 | 1, |
| 11972 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11973 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11974 | {kProxy, |
| 11975 | AUTH_SYNC, |
| 11976 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11977 | kSecureServer, |
| 11978 | AUTH_NONE, |
| 11979 | OK, |
| 11980 | 2, |
| 11981 | kNoSSL, |
| 11982 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11983 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11984 | {kProxy, |
| 11985 | AUTH_SYNC, |
| 11986 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11987 | kSecureServer, |
| 11988 | AUTH_NONE, |
| 11989 | OK, |
| 11990 | 2, |
| 11991 | kNoSSL, |
| 11992 | {TestRound(kConnect, kProxyChallenge, OK), |
| 11993 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11994 | {kProxy, |
| 11995 | AUTH_SYNC, |
| 11996 | ERR_UNEXPECTED, |
| 11997 | kSecureServer, |
| 11998 | AUTH_NONE, |
| 11999 | OK, |
| 12000 | 2, |
| 12001 | kNoSSL, |
| 12002 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12003 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12004 | {kProxy, |
| 12005 | AUTH_ASYNC, |
| 12006 | OK, |
| 12007 | kSecureServer, |
| 12008 | AUTH_NONE, |
| 12009 | OK, |
| 12010 | 2, |
| 12011 | 1, |
| 12012 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12013 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12014 | {kProxy, |
| 12015 | AUTH_ASYNC, |
| 12016 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12017 | kSecureServer, |
| 12018 | AUTH_NONE, |
| 12019 | OK, |
| 12020 | 2, |
| 12021 | kNoSSL, |
| 12022 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12023 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12024 | // Authenticating HTTPS server through an authenticating proxy. |
| 12025 | {kProxy, |
| 12026 | AUTH_SYNC, |
| 12027 | OK, |
| 12028 | kSecureServer, |
| 12029 | AUTH_SYNC, |
| 12030 | OK, |
| 12031 | 3, |
| 12032 | 1, |
| 12033 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12034 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12035 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12036 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12037 | {kProxy, |
| 12038 | AUTH_SYNC, |
| 12039 | OK, |
| 12040 | kSecureServer, |
| 12041 | AUTH_SYNC, |
| 12042 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12043 | 3, |
| 12044 | 1, |
| 12045 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12046 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12047 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12048 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12049 | {kProxy, |
| 12050 | AUTH_ASYNC, |
| 12051 | OK, |
| 12052 | kSecureServer, |
| 12053 | AUTH_SYNC, |
| 12054 | OK, |
| 12055 | 3, |
| 12056 | 1, |
| 12057 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12058 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12059 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12060 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12061 | {kProxy, |
| 12062 | AUTH_ASYNC, |
| 12063 | OK, |
| 12064 | kSecureServer, |
| 12065 | AUTH_SYNC, |
| 12066 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12067 | 3, |
| 12068 | 1, |
| 12069 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12070 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12071 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12072 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12073 | {kProxy, |
| 12074 | AUTH_SYNC, |
| 12075 | OK, |
| 12076 | kSecureServer, |
| 12077 | AUTH_ASYNC, |
| 12078 | OK, |
| 12079 | 3, |
| 12080 | 1, |
| 12081 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12082 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12083 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12084 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12085 | {kProxy, |
| 12086 | AUTH_SYNC, |
| 12087 | OK, |
| 12088 | kSecureServer, |
| 12089 | AUTH_ASYNC, |
| 12090 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12091 | 3, |
| 12092 | 1, |
| 12093 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12094 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12095 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12096 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12097 | {kProxy, |
| 12098 | AUTH_ASYNC, |
| 12099 | OK, |
| 12100 | kSecureServer, |
| 12101 | AUTH_ASYNC, |
| 12102 | OK, |
| 12103 | 3, |
| 12104 | 1, |
| 12105 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12106 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12107 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12108 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12109 | {kProxy, |
| 12110 | AUTH_ASYNC, |
| 12111 | OK, |
| 12112 | kSecureServer, |
| 12113 | AUTH_ASYNC, |
| 12114 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12115 | 3, |
| 12116 | 1, |
| 12117 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12118 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12119 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12120 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12121 | }; |
| 12122 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 12123 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12124 | SCOPED_TRACE(::testing::Message() << "Test config " << i); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12125 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12126 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12127 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12128 | SSLInfo empty_ssl_info; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12129 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12130 | |
| 12131 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12132 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12133 | for (int n = 0; n < 2; n++) { |
| 12134 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12135 | std::string auth_challenge = "Mock realm=proxy"; |
| 12136 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12137 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12138 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12139 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12140 | empty_ssl_info, origin, |
| 12141 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12142 | auth_handler->SetGenerateExpectation( |
| 12143 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 12144 | test_config.proxy_auth_rv); |
| 12145 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12146 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12147 | } |
| 12148 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12149 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12150 | std::string auth_challenge = "Mock realm=server"; |
| 12151 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12152 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12153 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12154 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12155 | empty_ssl_info, origin, |
| 12156 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12157 | auth_handler->SetGenerateExpectation( |
| 12158 | test_config.server_auth_timing == AUTH_ASYNC, |
| 12159 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12160 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12161 | |
| 12162 | // The second handler always succeeds. It should only be used where there |
| 12163 | // are multiple auth sessions for server auth in the same network |
| 12164 | // transaction using the same auth scheme. |
| 12165 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12166 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12167 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12168 | empty_ssl_info, origin, |
| 12169 | NetLogWithSource()); |
| 12170 | second_handler->SetGenerateExpectation(true, OK); |
| 12171 | auth_factory->AddMockHandler(second_handler.release(), |
| 12172 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12173 | } |
| 12174 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12175 | session_deps_.proxy_service = |
| 12176 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12177 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12178 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12179 | } |
| 12180 | |
| 12181 | HttpRequestInfo request; |
| 12182 | request.method = "GET"; |
| 12183 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12184 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12186 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12187 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12188 | |
| 12189 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12190 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12191 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12192 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12193 | |
| 12194 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12195 | mock_reads.back().push_back(read_write_round.read); |
| 12196 | mock_writes.back().push_back(read_write_round.write); |
| 12197 | |
| 12198 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12199 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12200 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12201 | mock_reads.push_back(std::vector<MockRead>()); |
| 12202 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12203 | } |
| 12204 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12205 | if (read_write_round.extra_read) { |
| 12206 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12207 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12208 | if (read_write_round.extra_write) { |
| 12209 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12210 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12211 | |
| 12212 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12213 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12214 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12215 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12216 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12217 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12218 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12219 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12220 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12221 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12222 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12223 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12224 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12225 | } |
| 12226 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12227 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12228 | // they are as well. |
| 12229 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12230 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12231 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12232 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12233 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12234 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12235 | int rv; |
| 12236 | if (round == 0) { |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12237 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12238 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12239 | rv = trans.RestartWithAuth( |
| 12240 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12241 | } |
| 12242 | if (rv == ERR_IO_PENDING) |
| 12243 | rv = callback.WaitForResult(); |
| 12244 | |
| 12245 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12246 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12247 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12248 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12249 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12250 | continue; |
| 12251 | } |
| 12252 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12253 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12254 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12255 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12256 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12257 | } |
| 12258 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12259 | } |
| 12260 | } |
| 12261 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12262 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12263 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12264 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12265 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12266 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12267 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12268 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12269 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12270 | |
| 12271 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12272 | auth_handler->set_connection_based(true); |
| 12273 | std::string auth_challenge = "Mock realm=server"; |
| 12274 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12275 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12276 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12277 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12278 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12279 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12280 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12281 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12282 | int rv = OK; |
| 12283 | const HttpResponseInfo* response = NULL; |
| 12284 | HttpRequestInfo request; |
| 12285 | request.method = "GET"; |
| 12286 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12289 | |
| 12290 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12291 | // to validate that the TCP socket is not released to the pool between |
| 12292 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12293 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12294 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12295 | 50, // Max sockets for pool |
| 12296 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12297 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12298 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12299 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12300 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12301 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12302 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12305 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12306 | |
| 12307 | const MockWrite kGet( |
| 12308 | "GET / HTTP/1.1\r\n" |
| 12309 | "Host: www.example.com\r\n" |
| 12310 | "Connection: keep-alive\r\n\r\n"); |
| 12311 | const MockWrite kGetAuth( |
| 12312 | "GET / HTTP/1.1\r\n" |
| 12313 | "Host: www.example.com\r\n" |
| 12314 | "Connection: keep-alive\r\n" |
| 12315 | "Authorization: auth_token\r\n\r\n"); |
| 12316 | |
| 12317 | const MockRead kServerChallenge( |
| 12318 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12319 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12320 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12321 | "Content-Length: 14\r\n\r\n" |
| 12322 | "Unauthorized\r\n"); |
| 12323 | const MockRead kSuccess( |
| 12324 | "HTTP/1.1 200 OK\r\n" |
| 12325 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12326 | "Content-Length: 3\r\n\r\n" |
| 12327 | "Yes"); |
| 12328 | |
| 12329 | MockWrite writes[] = { |
| 12330 | // First round |
| 12331 | kGet, |
| 12332 | // Second round |
| 12333 | kGetAuth, |
| 12334 | // Third round |
| 12335 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12336 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12337 | kGetAuth, |
| 12338 | // Competing request |
| 12339 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12340 | }; |
| 12341 | MockRead reads[] = { |
| 12342 | // First round |
| 12343 | kServerChallenge, |
| 12344 | // Second round |
| 12345 | kServerChallenge, |
| 12346 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12347 | kServerChallenge, |
| 12348 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12349 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12350 | // Competing response |
| 12351 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12352 | }; |
| 12353 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12354 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12355 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12356 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12357 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12358 | |
| 12359 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12360 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12361 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12362 | if (rv == ERR_IO_PENDING) |
| 12363 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12364 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12365 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12366 | ASSERT_TRUE(response); |
| 12367 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12368 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12369 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12370 | // In between rounds, another request comes in for the same domain. |
| 12371 | // It should not be able to grab the TCP socket that trans has already |
| 12372 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12373 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12374 | TestCompletionCallback callback_compete; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12375 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12376 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12378 | // callback_compete.WaitForResult at this point would stall forever, |
| 12379 | // since the HttpNetworkTransaction does not release the request back to |
| 12380 | // the pool until after authentication completes. |
| 12381 | |
| 12382 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12383 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12384 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12385 | if (rv == ERR_IO_PENDING) |
| 12386 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12387 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12388 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12389 | ASSERT_TRUE(response); |
| 12390 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12391 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12392 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12393 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12394 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12395 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12396 | if (rv == ERR_IO_PENDING) |
| 12397 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12398 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12399 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12400 | ASSERT_TRUE(response); |
| 12401 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12402 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12403 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12404 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12405 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12406 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12407 | if (rv == ERR_IO_PENDING) |
| 12408 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12409 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12410 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12411 | ASSERT_TRUE(response); |
| 12412 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12413 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12414 | |
| 12415 | // Read the body since the fourth round was successful. This will also |
| 12416 | // release the socket back to the pool. |
| 12417 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12418 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12419 | if (rv == ERR_IO_PENDING) |
| 12420 | rv = callback.WaitForResult(); |
| 12421 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12422 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12423 | EXPECT_EQ(0, rv); |
| 12424 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12425 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12426 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12427 | |
| 12428 | // The competing request can now finish. Wait for the headers and then |
| 12429 | // read the body. |
| 12430 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12431 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12432 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12433 | if (rv == ERR_IO_PENDING) |
| 12434 | rv = callback.WaitForResult(); |
| 12435 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12436 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12437 | EXPECT_EQ(0, rv); |
| 12438 | |
| 12439 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12440 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12441 | } |
| 12442 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12443 | // This tests the case that a request is issued via http instead of spdy after |
| 12444 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12445 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12446 | HttpRequestInfo request; |
| 12447 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12448 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12449 | |
| 12450 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12451 | MockWrite( |
| 12452 | "GET / HTTP/1.1\r\n" |
| 12453 | "Host: www.example.org\r\n" |
| 12454 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12455 | }; |
| 12456 | |
| 12457 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12458 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12459 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12460 | MockRead("\r\n"), |
| 12461 | MockRead("hello world"), |
| 12462 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12463 | }; |
| 12464 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12465 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12466 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12467 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12469 | |
| 12470 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12471 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12472 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12474 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12475 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12478 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12479 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12480 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12482 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12484 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12485 | ASSERT_TRUE(response); |
| 12486 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12487 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12488 | |
| 12489 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12490 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12491 | EXPECT_EQ("hello world", response_data); |
| 12492 | |
| 12493 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12494 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12495 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12496 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12497 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12498 | // immediate server closing of the socket. |
| 12499 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12500 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12501 | HttpRequestInfo request; |
| 12502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12503 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12504 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12505 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12506 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12508 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12509 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12510 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12511 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12512 | |
| 12513 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12514 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12515 | }; |
| 12516 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12517 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12518 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12519 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12521 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12522 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12525 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12526 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12527 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12528 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12529 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12530 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12531 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12532 | // it gets it. This is needed since the auth handler may get destroyed |
| 12533 | // before we get a chance to query it. |
| 12534 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12535 | public: |
| 12536 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12537 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12538 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12539 | |
| 12540 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12541 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12542 | const HttpRequestInfo* request, |
| 12543 | const CompletionCallback& callback, |
| 12544 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12545 | *url_ = request->url; |
| 12546 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12547 | credentials, request, callback, auth_token); |
| 12548 | } |
| 12549 | |
| 12550 | private: |
| 12551 | GURL* url_; |
| 12552 | }; |
| 12553 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12554 | // Test that if we cancel the transaction as the connection is completing, that |
| 12555 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12556 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12557 | // Setup everything about the connection to complete synchronously, so that |
| 12558 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12559 | // for is the callback from the HttpStreamRequest. |
| 12560 | // Then cancel the transaction. |
| 12561 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12562 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12563 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12564 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12565 | MockRead(SYNCHRONOUS, "hello world"), |
| 12566 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12567 | }; |
| 12568 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12569 | HttpRequestInfo request; |
| 12570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12571 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12572 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12573 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12575 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12576 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12577 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12578 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12579 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12580 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12582 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12583 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12584 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12585 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12587 | trans.reset(); // Cancel the transaction here. |
| 12588 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12589 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12590 | } |
| 12591 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12592 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12593 | // stream is drained properly and added back to the socket pool. The main |
| 12594 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12595 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12596 | // deleted. |
| 12597 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12598 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12599 | MockRead data_reads[] = { |
| 12600 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12601 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12602 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12603 | MockRead(ASYNC, "1"), |
| 12604 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12605 | // HttpNetworkTransaction has been deleted. |
| 12606 | MockRead(ASYNC, "2"), |
| 12607 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12608 | }; |
| 12609 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12611 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12613 | |
| 12614 | { |
| 12615 | HttpRequestInfo request; |
| 12616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12617 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12618 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12619 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12620 | TestCompletionCallback callback; |
| 12621 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12622 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12624 | callback.WaitForResult(); |
| 12625 | |
| 12626 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12627 | ASSERT_TRUE(response); |
| 12628 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12629 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12630 | |
| 12631 | // The transaction and HttpRequestInfo are deleted. |
| 12632 | } |
| 12633 | |
| 12634 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12635 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12636 | |
| 12637 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12638 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12639 | } |
| 12640 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12641 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12642 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12643 | session_deps_.proxy_service = |
| 12644 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12645 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12646 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12648 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12649 | HttpRequestInfo request; |
| 12650 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12651 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12652 | |
| 12653 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12654 | MockWrite( |
| 12655 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12656 | "Host: www.example.org\r\n" |
| 12657 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12658 | }; |
| 12659 | |
| 12660 | MockRead data_reads1[] = { |
| 12661 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12662 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12663 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12665 | }; |
| 12666 | |
| 12667 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12668 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12669 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12671 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12674 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12675 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12676 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12677 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12679 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12681 | |
| 12682 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12683 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12686 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12687 | |
| 12688 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12689 | EXPECT_EQ(200, response->headers->response_code()); |
| 12690 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12691 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12692 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12693 | HostPortPair::FromString("myproxy:70")), |
| 12694 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12695 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12696 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12697 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12698 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12699 | |
| 12700 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12701 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12702 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12703 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12704 | } |
| 12705 | |
| 12706 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12707 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12708 | session_deps_.proxy_service = |
| 12709 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12710 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12711 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12713 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12714 | HttpRequestInfo request; |
| 12715 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12716 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12717 | |
| 12718 | // Since we have proxy, should try to establish tunnel. |
| 12719 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12720 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12721 | "Host: www.example.org:443\r\n" |
| 12722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12723 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12724 | MockWrite("GET / HTTP/1.1\r\n" |
| 12725 | "Host: www.example.org\r\n" |
| 12726 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12727 | }; |
| 12728 | |
| 12729 | MockRead data_reads1[] = { |
| 12730 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12731 | |
| 12732 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12733 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12734 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12735 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12736 | }; |
| 12737 | |
| 12738 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12739 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12740 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12741 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12744 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12747 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12748 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12749 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12750 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12752 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12754 | |
| 12755 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12756 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12757 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12758 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12759 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12760 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12761 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12762 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12763 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12764 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12765 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12767 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12768 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12769 | |
| 12770 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12771 | EXPECT_EQ(200, response->headers->response_code()); |
| 12772 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12773 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12774 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12775 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12776 | HostPortPair::FromString("myproxy:70")), |
| 12777 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12778 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12779 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12780 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12781 | |
| 12782 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12783 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12784 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12785 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12786 | } |
| 12787 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12788 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12789 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12790 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12791 | session_deps_.proxy_service = |
| 12792 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12793 | BoundTestNetLog log; |
| 12794 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12795 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12796 | |
| 12797 | HttpRequestInfo request; |
| 12798 | request.method = "GET"; |
| 12799 | request.url = GURL("https://[::1]:443/"); |
| 12800 | |
| 12801 | // Since we have proxy, should try to establish tunnel. |
| 12802 | MockWrite data_writes1[] = { |
| 12803 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12804 | "Host: [::1]:443\r\n" |
| 12805 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12806 | |
| 12807 | MockWrite("GET / HTTP/1.1\r\n" |
| 12808 | "Host: [::1]\r\n" |
| 12809 | "Connection: keep-alive\r\n\r\n"), |
| 12810 | }; |
| 12811 | |
| 12812 | MockRead data_reads1[] = { |
| 12813 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12814 | |
| 12815 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12817 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12818 | MockRead(SYNCHRONOUS, OK), |
| 12819 | }; |
| 12820 | |
| 12821 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12822 | data_writes1, arraysize(data_writes1)); |
| 12823 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12824 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12826 | |
| 12827 | TestCompletionCallback callback1; |
| 12828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12831 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12833 | |
| 12834 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12835 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12836 | TestNetLogEntry::List entries; |
| 12837 | log.GetEntries(&entries); |
| 12838 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12839 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12840 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12841 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12842 | entries, pos, |
| 12843 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12844 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12846 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12847 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12848 | |
| 12849 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12850 | EXPECT_EQ(200, response->headers->response_code()); |
| 12851 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12852 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12853 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12854 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12855 | HostPortPair::FromString("myproxy:70")), |
| 12856 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12857 | |
| 12858 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12859 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12860 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12861 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12862 | } |
| 12863 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12864 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12865 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12866 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12867 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12868 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12869 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12871 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12872 | HttpRequestInfo request; |
| 12873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12874 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12875 | |
| 12876 | // Since we have proxy, should try to establish tunnel. |
| 12877 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12878 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12879 | "Host: www.example.org:443\r\n" |
| 12880 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12881 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12882 | MockWrite("GET / HTTP/1.1\r\n" |
| 12883 | "Host: www.example.org\r\n" |
| 12884 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12885 | }; |
| 12886 | |
| 12887 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12888 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12889 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12890 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12891 | }; |
| 12892 | |
| 12893 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12894 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12896 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12899 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12903 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12905 | |
| 12906 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12907 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12908 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12909 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12910 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12911 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12912 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12913 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12914 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12915 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12916 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12917 | } |
| 12918 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12919 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12920 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12921 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12922 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12923 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12924 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12925 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12926 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12927 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12928 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12929 | }; |
| 12930 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12931 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12932 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12933 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12934 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12935 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12936 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12940 | |
| 12941 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12942 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12943 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12944 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12945 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12946 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12947 | |
| 12948 | HttpRequestInfo request; |
| 12949 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12950 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12951 | |
| 12952 | // This is the important line that marks this as a preconnect. |
| 12953 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12955 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12956 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12957 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12960 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12961 | } |
| 12962 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12963 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12964 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12965 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12966 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12967 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12968 | request_info.url = GURL("https://www.example.com/"); |
| 12969 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12970 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12971 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12972 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12973 | MockWrite data_writes[] = { |
| 12974 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12975 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12976 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12977 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12983 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12984 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12985 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12986 | rv = callback.WaitForResult(); |
| 12987 | ASSERT_EQ(error, rv); |
| 12988 | } |
| 12989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12990 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12991 | // Just check a grab bag of cert errors. |
| 12992 | static const int kErrors[] = { |
| 12993 | ERR_CERT_COMMON_NAME_INVALID, |
| 12994 | ERR_CERT_AUTHORITY_INVALID, |
| 12995 | ERR_CERT_DATE_INVALID, |
| 12996 | }; |
| 12997 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12998 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12999 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13000 | } |
| 13001 | } |
| 13002 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13003 | // Ensure that a client certificate is removed from the SSL client auth |
| 13004 | // cache when: |
| 13005 | // 1) No proxy is involved. |
| 13006 | // 2) TLS False Start is disabled. |
| 13007 | // 3) The initial TLS handshake requests a client certificate. |
| 13008 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13009 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13010 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13011 | request_info.url = GURL("https://www.example.com/"); |
| 13012 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13013 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13014 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13015 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13016 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13017 | |
| 13018 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13019 | // CertificateRequest is received for the first time, the handshake will |
| 13020 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13021 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13022 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13023 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13024 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13025 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13026 | |
| 13027 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13028 | // False Start is not being used, the result of the SSL handshake will be |
| 13029 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13030 | // matches the result of a server sending a handshake_failure alert, |
| 13031 | // rather than a Finished message, because it requires a client |
| 13032 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13033 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13034 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13036 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13037 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13038 | |
| 13039 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13040 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13041 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13042 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13043 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13044 | // requiring a client certificate, this fallback handshake should also |
| 13045 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13046 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13047 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13049 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13050 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13051 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13052 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13053 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13054 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13055 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13056 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13057 | // requiring a client certificate, this fallback handshake should also |
| 13058 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13059 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13060 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13062 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13063 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13067 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13068 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13069 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13070 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13071 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13072 | |
| 13073 | // Complete the SSL handshake, which should abort due to requiring a |
| 13074 | // client certificate. |
| 13075 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13076 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13077 | |
| 13078 | // Indicate that no certificate should be supplied. From the perspective |
| 13079 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13080 | // certificate, so this is the same as supply a |
| 13081 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13082 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13083 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13084 | |
| 13085 | // Ensure the certificate was added to the client auth cache before |
| 13086 | // allowing the connection to continue restarting. |
| 13087 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13088 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13089 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13090 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13091 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13092 | |
| 13093 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13094 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13095 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13096 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13097 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13098 | |
| 13099 | // Ensure that the client certificate is removed from the cache on a |
| 13100 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13101 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13102 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13103 | } |
| 13104 | |
| 13105 | // Ensure that a client certificate is removed from the SSL client auth |
| 13106 | // cache when: |
| 13107 | // 1) No proxy is involved. |
| 13108 | // 2) TLS False Start is enabled. |
| 13109 | // 3) The initial TLS handshake requests a client certificate. |
| 13110 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13111 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13112 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13113 | request_info.url = GURL("https://www.example.com/"); |
| 13114 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13115 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13116 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13117 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13118 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13119 | |
| 13120 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13121 | // return successfully after reading up to the peer's Certificate message. |
| 13122 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13123 | // enqueue application data to be sent in the same packet as the |
| 13124 | // ChangeCipherSpec and Finished messages. |
| 13125 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13126 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13127 | // Finished messages. If there was an error negotiating with the peer, |
| 13128 | // such as due to the peer requiring a client certificate when none was |
| 13129 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13130 | // called. |
| 13131 | |
| 13132 | // Like the non-False Start case, when a client certificate is requested by |
| 13133 | // the peer, the handshake is aborted during the Connect() call. |
| 13134 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13135 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13136 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13138 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13139 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13140 | |
| 13141 | // When a client certificate is supplied, Connect() will not be aborted |
| 13142 | // when the peer requests the certificate. Instead, the handshake will |
| 13143 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13144 | // the socket. The handshake messages are not processed until Read() is |
| 13145 | // called, which then detects that the handshake was aborted, due to the |
| 13146 | // peer sending a handshake_failure because it requires a client |
| 13147 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13148 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13149 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13151 | MockRead data2_reads[] = { |
| 13152 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13153 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13154 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13155 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13156 | |
| 13157 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13158 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13159 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13160 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13161 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13163 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13164 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13165 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13166 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13167 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13168 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13169 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13171 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13172 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13173 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13174 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13175 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13176 | ssl_data5.cert_request_info = cert_request.get(); |
| 13177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13178 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13179 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13180 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13183 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13184 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13185 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13186 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13187 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13188 | |
| 13189 | // Complete the SSL handshake, which should abort due to requiring a |
| 13190 | // client certificate. |
| 13191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13192 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13193 | |
| 13194 | // Indicate that no certificate should be supplied. From the perspective |
| 13195 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13196 | // certificate, so this is the same as supply a |
| 13197 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13198 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13199 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13200 | |
| 13201 | // Ensure the certificate was added to the client auth cache before |
| 13202 | // allowing the connection to continue restarting. |
| 13203 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13204 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13205 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13206 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13207 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13208 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13209 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13210 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13211 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13212 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13213 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13214 | |
| 13215 | // Ensure that the client certificate is removed from the cache on a |
| 13216 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13217 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13218 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13219 | } |
| 13220 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13221 | // Ensure that a client certificate is removed from the SSL client auth |
| 13222 | // cache when: |
| 13223 | // 1) An HTTPS proxy is involved. |
| 13224 | // 3) The HTTPS proxy requests a client certificate. |
| 13225 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13226 | // proxy. |
| 13227 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13228 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13229 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13230 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13231 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13232 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13233 | |
| 13234 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13235 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13236 | |
| 13237 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13238 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13239 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13240 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13241 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13242 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13243 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13244 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13246 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13247 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13248 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13250 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13252 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13253 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13254 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13255 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13256 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13258 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13260 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13261 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13262 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13263 | requests[0].url = GURL("https://www.example.com/"); |
| 13264 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13265 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13266 | |
| 13267 | requests[1].url = GURL("http://www.example.com/"); |
| 13268 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13269 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13270 | |
| 13271 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13272 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13275 | |
| 13276 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13277 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13278 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13279 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13280 | |
| 13281 | // Complete the SSL handshake, which should abort due to requiring a |
| 13282 | // client certificate. |
| 13283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13284 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13285 | |
| 13286 | // Indicate that no certificate should be supplied. From the perspective |
| 13287 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13288 | // certificate, so this is the same as supply a |
| 13289 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13290 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13291 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13292 | |
| 13293 | // Ensure the certificate was added to the client auth cache before |
| 13294 | // allowing the connection to continue restarting. |
| 13295 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13296 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13297 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13298 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13299 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13300 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13301 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13302 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13303 | HostPortPair("www.example.com", 443), &client_cert, |
| 13304 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13305 | |
| 13306 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13307 | // then consume ssl_data3, which should also fail. The result code is |
| 13308 | // checked against what ssl_data3 should return. |
| 13309 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13310 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13311 | |
| 13312 | // Now that the new handshake has failed, ensure that the client |
| 13313 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13314 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13315 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13316 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13317 | HostPortPair("www.example.com", 443), &client_cert, |
| 13318 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13319 | } |
| 13320 | } |
| 13321 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13322 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13323 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13324 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13326 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13327 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13328 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13329 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13330 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13331 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13332 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13333 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13334 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13335 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13336 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13337 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13338 | SpdySerializedFrame host1_resp_body( |
| 13339 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13340 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13341 | SpdySerializedFrame host2_resp_body( |
| 13342 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13343 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13344 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13345 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13346 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13347 | }; |
| 13348 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13349 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13350 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13351 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13352 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13353 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13354 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13355 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13356 | HttpRequestInfo request1; |
| 13357 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13358 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13359 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13360 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13361 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13362 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13364 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13365 | |
| 13366 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13367 | ASSERT_TRUE(response); |
| 13368 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13369 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13370 | |
| 13371 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13372 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13373 | EXPECT_EQ("hello!", response_data); |
| 13374 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13375 | // Preload mail.example.com into HostCache. |
| 13376 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13377 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13378 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13379 | std::unique_ptr<HostResolver::Request> request; |
| 13380 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13381 | &ignored, callback.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13382 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13383 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13386 | |
| 13387 | HttpRequestInfo request2; |
| 13388 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13389 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13390 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13391 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13392 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13393 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13395 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13396 | |
| 13397 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13398 | ASSERT_TRUE(response); |
| 13399 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13400 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13401 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13402 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13403 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13404 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13405 | } |
| 13406 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13407 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13408 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13409 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13411 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13412 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13413 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13414 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13415 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13416 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13417 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13418 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13419 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13420 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13421 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13422 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13423 | SpdySerializedFrame host1_resp_body( |
| 13424 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13425 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13426 | SpdySerializedFrame host2_resp_body( |
| 13427 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13428 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13429 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13430 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13431 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13432 | }; |
| 13433 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13434 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13435 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13436 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13437 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13438 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13439 | |
| 13440 | TestCompletionCallback callback; |
| 13441 | HttpRequestInfo request1; |
| 13442 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13443 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13444 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13445 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13446 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13447 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13449 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13450 | |
| 13451 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13452 | ASSERT_TRUE(response); |
| 13453 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13454 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13455 | |
| 13456 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13457 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13458 | EXPECT_EQ("hello!", response_data); |
| 13459 | |
| 13460 | HttpRequestInfo request2; |
| 13461 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13462 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13463 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13464 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13465 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13466 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13468 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13469 | |
| 13470 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13471 | ASSERT_TRUE(response); |
| 13472 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13473 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13474 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13475 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13476 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13477 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13478 | } |
| 13479 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13480 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13481 | public: |
| 13482 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13483 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13484 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13485 | |
| 13486 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13487 | |
| 13488 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13489 | int Resolve(const RequestInfo& info, |
| 13490 | RequestPriority priority, |
| 13491 | AddressList* addresses, |
| 13492 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13493 | std::unique_ptr<Request>* out_req, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13494 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13495 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13496 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13497 | } |
| 13498 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13499 | int ResolveFromCache(const RequestInfo& info, |
| 13500 | AddressList* addresses, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13501 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13502 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13503 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13504 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13505 | return rv; |
| 13506 | } |
| 13507 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13508 | MockCachingHostResolver* GetMockHostResolver() { |
| 13509 | return &host_resolver_; |
| 13510 | } |
| 13511 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13512 | private: |
| 13513 | MockCachingHostResolver host_resolver_; |
| 13514 | const HostPortPair host_port_; |
| 13515 | }; |
| 13516 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13517 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13518 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13519 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13520 | OneTimeCachingHostResolver host_resolver( |
| 13521 | HostPortPair("mail.example.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13522 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13523 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13524 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13526 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13527 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13528 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13529 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13530 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13531 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13532 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13533 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13534 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13535 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13536 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13537 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13538 | SpdySerializedFrame host1_resp_body( |
| 13539 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13540 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13541 | SpdySerializedFrame host2_resp_body( |
| 13542 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13543 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13544 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13545 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13546 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13547 | }; |
| 13548 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13549 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13550 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13551 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13552 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13553 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13554 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13555 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13556 | HttpRequestInfo request1; |
| 13557 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13558 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13559 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13560 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13561 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13562 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13564 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13565 | |
| 13566 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13567 | ASSERT_TRUE(response); |
| 13568 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13569 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13570 | |
| 13571 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13572 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13573 | EXPECT_EQ("hello!", response_data); |
| 13574 | |
| 13575 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13576 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13577 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13578 | std::unique_ptr<HostResolver::Request> request; |
| 13579 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13580 | callback.callback(), &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13584 | |
| 13585 | HttpRequestInfo request2; |
| 13586 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13587 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13588 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13589 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13590 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13591 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13593 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13594 | |
| 13595 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13596 | ASSERT_TRUE(response); |
| 13597 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13598 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13599 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13600 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13601 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13602 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13603 | } |
| 13604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13605 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13606 | const std::string https_url = "https://www.example.org:8080/"; |
| 13607 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13608 | |
| 13609 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13610 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13611 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13612 | |
| 13613 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13614 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13615 | }; |
| 13616 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13617 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13618 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13619 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13620 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13621 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13622 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13623 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13624 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13625 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13626 | |
| 13627 | // HTTP GET for the HTTP URL |
| 13628 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13629 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13630 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13631 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13632 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13633 | }; |
| 13634 | |
| 13635 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13636 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13637 | MockRead(ASYNC, 2, "hello"), |
| 13638 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13639 | }; |
| 13640 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13641 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13642 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13643 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13644 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13645 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13647 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13648 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13651 | |
| 13652 | // Start the first transaction to set up the SpdySession |
| 13653 | HttpRequestInfo request1; |
| 13654 | request1.method = "GET"; |
| 13655 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13656 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13657 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13658 | TestCompletionCallback callback1; |
| 13659 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13660 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13661 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13662 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13663 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13664 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13665 | |
| 13666 | // Now, start the HTTP request |
| 13667 | HttpRequestInfo request2; |
| 13668 | request2.method = "GET"; |
| 13669 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13670 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13671 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13672 | TestCompletionCallback callback2; |
| 13673 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13674 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13675 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13676 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13677 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13678 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13679 | } |
| 13680 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13681 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13682 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13683 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13684 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13685 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13686 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13687 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13688 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13689 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13691 | |
| 13692 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13693 | // negotiated. |
| 13694 | StaticSocketDataProvider data; |
| 13695 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13696 | |
| 13697 | // 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] | 13698 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13699 | // mocked. This way the request relies on the alternate Job. |
| 13700 | StaticSocketDataProvider data_refused; |
| 13701 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13702 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13703 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13704 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13706 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13707 | session->http_server_properties(); |
| 13708 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13709 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13710 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13711 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13712 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13715 | HttpRequestInfo request; |
| 13716 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13717 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13718 | TestCompletionCallback callback; |
| 13719 | |
| 13720 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13721 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13722 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13723 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13724 | } |
| 13725 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13726 | // 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] | 13727 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13728 | // succeeds, the request should succeed, even if the latter fails because |
| 13729 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13730 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13731 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13732 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13733 | |
| 13734 | // Negotiate HTTP/1.1 with alternative. |
| 13735 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13736 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13738 | |
| 13739 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13740 | // negotiated. |
| 13741 | StaticSocketDataProvider data; |
| 13742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13743 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13744 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13745 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13746 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13748 | |
| 13749 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13750 | MockWrite("GET / HTTP/1.1\r\n" |
| 13751 | "Host: www.example.org\r\n" |
| 13752 | "Connection: keep-alive\r\n\r\n"), |
| 13753 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13754 | "Host: www.example.org\r\n" |
| 13755 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13756 | }; |
| 13757 | |
| 13758 | MockRead http_reads[] = { |
| 13759 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13760 | MockRead("Content-Type: text/html\r\n"), |
| 13761 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13762 | MockRead("foobar"), |
| 13763 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13764 | MockRead("Content-Type: text/html\r\n"), |
| 13765 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13766 | MockRead("another"), |
| 13767 | }; |
| 13768 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13769 | http_writes, arraysize(http_writes)); |
| 13770 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13771 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13772 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13774 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13775 | session->http_server_properties(); |
| 13776 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13777 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13778 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13779 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13780 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13781 | |
| 13782 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13783 | HttpRequestInfo request1; |
| 13784 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13785 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13786 | request1.load_flags = 0; |
| 13787 | TestCompletionCallback callback1; |
| 13788 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13789 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13790 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13791 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13792 | |
| 13793 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13794 | ASSERT_TRUE(response1); |
| 13795 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13796 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13797 | |
| 13798 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13799 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13800 | EXPECT_EQ("foobar", response_data1); |
| 13801 | |
| 13802 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13803 | // for alternative service. |
| 13804 | EXPECT_TRUE( |
| 13805 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13806 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13807 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13808 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13809 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13810 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13811 | HttpRequestInfo request2; |
| 13812 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13813 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13814 | request2.load_flags = 0; |
| 13815 | TestCompletionCallback callback2; |
| 13816 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13817 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13818 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13819 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13820 | |
| 13821 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13822 | ASSERT_TRUE(response2); |
| 13823 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13824 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13825 | |
| 13826 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13827 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13828 | EXPECT_EQ("another", response_data2); |
| 13829 | } |
| 13830 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13831 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13832 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13833 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13834 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13835 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13836 | HostPortPair alternative("alternative.example.org", 443); |
| 13837 | std::string origin_url = "https://origin.example.org:443"; |
| 13838 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13839 | |
| 13840 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13841 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13842 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13844 | |
| 13845 | // HTTP/1.1 data for |request1| and |request2|. |
| 13846 | MockWrite http_writes[] = { |
| 13847 | MockWrite( |
| 13848 | "GET / HTTP/1.1\r\n" |
| 13849 | "Host: alternative.example.org\r\n" |
| 13850 | "Connection: keep-alive\r\n\r\n"), |
| 13851 | MockWrite( |
| 13852 | "GET / HTTP/1.1\r\n" |
| 13853 | "Host: alternative.example.org\r\n" |
| 13854 | "Connection: keep-alive\r\n\r\n"), |
| 13855 | }; |
| 13856 | |
| 13857 | MockRead http_reads[] = { |
| 13858 | MockRead( |
| 13859 | "HTTP/1.1 200 OK\r\n" |
| 13860 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13861 | "Content-Length: 40\r\n\r\n" |
| 13862 | "first HTTP/1.1 response from alternative"), |
| 13863 | MockRead( |
| 13864 | "HTTP/1.1 200 OK\r\n" |
| 13865 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13866 | "Content-Length: 41\r\n\r\n" |
| 13867 | "second HTTP/1.1 response from alternative"), |
| 13868 | }; |
| 13869 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13870 | http_writes, arraysize(http_writes)); |
| 13871 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13872 | |
| 13873 | // This test documents that an alternate Job should not pool to an already |
| 13874 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13875 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13876 | StaticSocketDataProvider data_refused; |
| 13877 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13878 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13879 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13880 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13882 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13883 | session->http_server_properties(); |
| 13884 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13885 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13886 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13887 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13888 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13889 | |
| 13890 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13891 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13892 | HttpRequestInfo request1; |
| 13893 | request1.method = "GET"; |
| 13894 | request1.url = GURL(alternative_url); |
| 13895 | request1.load_flags = 0; |
| 13896 | TestCompletionCallback callback1; |
| 13897 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13898 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13899 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13900 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13901 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13902 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13903 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13904 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13905 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13906 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13907 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13908 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13909 | |
| 13910 | // Request for origin.example.org, which has an alternative service. This |
| 13911 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13912 | // 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] | 13913 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13914 | // this request fails. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13915 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13916 | HttpRequestInfo request2; |
| 13917 | request2.method = "GET"; |
| 13918 | request2.url = GURL(origin_url); |
| 13919 | request2.load_flags = 0; |
| 13920 | TestCompletionCallback callback2; |
| 13921 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13922 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13923 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13924 | |
| 13925 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13926 | // socket is still open and in the pool. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13927 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13928 | HttpRequestInfo request3; |
| 13929 | request3.method = "GET"; |
| 13930 | request3.url = GURL(alternative_url); |
| 13931 | request3.load_flags = 0; |
| 13932 | TestCompletionCallback callback3; |
| 13933 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13934 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13935 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13936 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13937 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13938 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13939 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13940 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13941 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13942 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13943 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13944 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13945 | } |
| 13946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13947 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13948 | const std::string https_url = "https://www.example.org:8080/"; |
| 13949 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13950 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13951 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13952 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13953 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13954 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13955 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13956 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13957 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13958 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13959 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13960 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13961 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13962 | |
| 13963 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13964 | SpdyHeaderBlock req2_block; |
| 13965 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13966 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13967 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13968 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13969 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13970 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13971 | |
| 13972 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13973 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 13974 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13975 | }; |
| 13976 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13977 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13978 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13979 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13980 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13981 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 13982 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13983 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13984 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13985 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13986 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13987 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13988 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13989 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13990 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13991 | CreateMockRead(wrapped_resp1, 4), |
| 13992 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13993 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13994 | CreateMockRead(resp2, 8), |
| 13995 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13996 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13997 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13998 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13999 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14000 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14001 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14002 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14003 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14004 | session_deps_.proxy_service = |
| 14005 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14006 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14007 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14008 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14009 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14011 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14012 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14013 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14014 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14015 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14016 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14017 | |
| 14018 | // Start the first transaction to set up the SpdySession |
| 14019 | HttpRequestInfo request1; |
| 14020 | request1.method = "GET"; |
| 14021 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14022 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14023 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14024 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14025 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14026 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14027 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14028 | data1.RunUntilPaused(); |
| 14029 | base::RunLoop().RunUntilIdle(); |
| 14030 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14031 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14032 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14033 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14034 | LoadTimingInfo load_timing_info1; |
| 14035 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14036 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14037 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14038 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14039 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14040 | HttpRequestInfo request2; |
| 14041 | request2.method = "GET"; |
| 14042 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14043 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14044 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14045 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14046 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14047 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14048 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14049 | data1.RunUntilPaused(); |
| 14050 | base::RunLoop().RunUntilIdle(); |
| 14051 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14052 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14053 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14054 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14055 | |
| 14056 | LoadTimingInfo load_timing_info2; |
| 14057 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14058 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14059 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14060 | // HTTP requests over a SPDY session should have a different connection |
| 14061 | // socket_log_id than requests over a tunnel. |
| 14062 | 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] | 14063 | } |
| 14064 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14065 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14066 | // that we do not pool other origins that resolve to the same IP when |
| 14067 | // the certificate does not match the new origin. |
| 14068 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14069 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14070 | const std::string url1 = "http://www.example.org/"; |
| 14071 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14072 | const std::string ip_addr = "1.2.3.4"; |
| 14073 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14074 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14075 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14076 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14077 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14078 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14079 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14080 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14081 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14082 | |
| 14083 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14084 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14085 | }; |
| 14086 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14087 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14088 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14089 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14090 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14091 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14092 | }; |
| 14093 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14094 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14095 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14096 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14097 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14098 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14099 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14100 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14101 | |
| 14102 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14103 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14104 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14105 | |
| 14106 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14107 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14108 | }; |
| 14109 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14110 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14111 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14112 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14113 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14114 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14115 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14116 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14117 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14118 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14119 | |
| 14120 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14121 | // all others direct. |
| 14122 | ProxyConfig proxy_config; |
| 14123 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14124 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14125 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 14126 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14127 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14128 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14129 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14130 | // Load a valid cert. Note, that this does not need to |
| 14131 | // be valid for proxy because the MockSSLClientSocket does |
| 14132 | // not actually verify it. But SpdySession will use this |
| 14133 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14134 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14135 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14136 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14137 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14138 | |
| 14139 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14140 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14142 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14143 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14144 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14145 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14146 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14147 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14148 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14149 | |
| 14150 | // Start the first transaction to set up the SpdySession |
| 14151 | HttpRequestInfo request1; |
| 14152 | request1.method = "GET"; |
| 14153 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14154 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14155 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14156 | TestCompletionCallback callback1; |
| 14157 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14158 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14159 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14160 | data1.RunUntilPaused(); |
| 14161 | base::RunLoop().RunUntilIdle(); |
| 14162 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14163 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14164 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14165 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14166 | |
| 14167 | // Now, start the HTTP request |
| 14168 | HttpRequestInfo request2; |
| 14169 | request2.method = "GET"; |
| 14170 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14171 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14172 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14173 | TestCompletionCallback callback2; |
| 14174 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14175 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14176 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14177 | |
| 14178 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14179 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14180 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14181 | } |
| 14182 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14183 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14184 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14185 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14186 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14187 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14188 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14189 | |
| 14190 | MockRead reads1[] = { |
| 14191 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14192 | }; |
| 14193 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14194 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14195 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14196 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14197 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14198 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14199 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14200 | }; |
| 14201 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14202 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14203 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14204 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14205 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14206 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14207 | }; |
| 14208 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14209 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14210 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14211 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14212 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14213 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14215 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14216 | |
| 14217 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14218 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14220 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14222 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14223 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14224 | |
| 14225 | // Start the first transaction to set up the SpdySession and verify that |
| 14226 | // connection was closed. |
| 14227 | HttpRequestInfo request1; |
| 14228 | request1.method = "GET"; |
| 14229 | request1.url = GURL(https_url); |
| 14230 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14231 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14232 | TestCompletionCallback callback1; |
| 14233 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14234 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14235 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14236 | |
| 14237 | // Now, start the second request and make sure it succeeds. |
| 14238 | HttpRequestInfo request2; |
| 14239 | request2.method = "GET"; |
| 14240 | request2.url = GURL(https_url); |
| 14241 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14242 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14243 | TestCompletionCallback callback2; |
| 14244 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14245 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14246 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14247 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14248 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14249 | } |
| 14250 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14251 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14252 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14253 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14254 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14255 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14256 | |
| 14257 | // Use two different hosts with different IPs so they don't get pooled. |
| 14258 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14259 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14261 | |
| 14262 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14263 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14264 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14265 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14268 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14269 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14270 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14271 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14272 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14273 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14274 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14275 | SpdySerializedFrame host1_resp_body( |
| 14276 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14277 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14278 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14279 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14280 | }; |
| 14281 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14282 | // Use a separate test instance for the separate SpdySession that will be |
| 14283 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14284 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14285 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14286 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14287 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14288 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14289 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14290 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14291 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14292 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14293 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14294 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14295 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14296 | SpdySerializedFrame host2_resp_body( |
| 14297 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14298 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14299 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14300 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14301 | }; |
| 14302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14303 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14304 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14305 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14306 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14307 | |
| 14308 | MockWrite http_write[] = { |
| 14309 | MockWrite("GET / HTTP/1.1\r\n" |
| 14310 | "Host: www.a.com\r\n" |
| 14311 | "Connection: keep-alive\r\n\r\n"), |
| 14312 | }; |
| 14313 | |
| 14314 | MockRead http_read[] = { |
| 14315 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14316 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14317 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14318 | MockRead("hello!"), |
| 14319 | }; |
| 14320 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14321 | http_write, arraysize(http_write)); |
| 14322 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14323 | |
| 14324 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14325 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14326 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14327 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14328 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14329 | |
| 14330 | TestCompletionCallback callback; |
| 14331 | HttpRequestInfo request1; |
| 14332 | request1.method = "GET"; |
| 14333 | request1.url = GURL("https://www.a.com/"); |
| 14334 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14335 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14336 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14337 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14338 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14339 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14340 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14341 | |
| 14342 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14343 | ASSERT_TRUE(response); |
| 14344 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14345 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14346 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14347 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14348 | |
| 14349 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14350 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14351 | EXPECT_EQ("hello!", response_data); |
| 14352 | trans.reset(); |
| 14353 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14354 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14355 | |
| 14356 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14357 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14358 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14359 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14360 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14361 | HttpRequestInfo request2; |
| 14362 | request2.method = "GET"; |
| 14363 | request2.url = GURL("https://www.b.com/"); |
| 14364 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14365 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14366 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14367 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14369 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14370 | |
| 14371 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14372 | ASSERT_TRUE(response); |
| 14373 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14374 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14375 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14376 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14377 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14378 | EXPECT_EQ("hello!", response_data); |
| 14379 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14380 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14381 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14382 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14383 | |
| 14384 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14385 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14386 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14387 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14388 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14389 | HttpRequestInfo request3; |
| 14390 | request3.method = "GET"; |
| 14391 | request3.url = GURL("http://www.a.com/"); |
| 14392 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14393 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14394 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14395 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14397 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14398 | |
| 14399 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14400 | ASSERT_TRUE(response); |
| 14401 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14402 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14403 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14404 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14405 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14406 | EXPECT_EQ("hello!", response_data); |
| 14407 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14408 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14409 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14410 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14411 | } |
| 14412 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14413 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14414 | HttpRequestInfo request; |
| 14415 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14416 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14420 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14421 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14422 | StaticSocketDataProvider data; |
| 14423 | data.set_connect_data(mock_connect); |
| 14424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14425 | |
| 14426 | TestCompletionCallback callback; |
| 14427 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14428 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14430 | |
| 14431 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14432 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14433 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14434 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14435 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14436 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14437 | |
| 14438 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14439 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14440 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14441 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14442 | |
| 14443 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14444 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14445 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14446 | } |
| 14447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14448 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14449 | HttpRequestInfo request; |
| 14450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14451 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14455 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14456 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14457 | StaticSocketDataProvider data; |
| 14458 | data.set_connect_data(mock_connect); |
| 14459 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14460 | |
| 14461 | TestCompletionCallback callback; |
| 14462 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14463 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14465 | |
| 14466 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14467 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14468 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14469 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14470 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14471 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14472 | |
| 14473 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14474 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14475 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14476 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14477 | |
| 14478 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14479 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14480 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14481 | } |
| 14482 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14483 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14484 | HttpRequestInfo request; |
| 14485 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14486 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14489 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14490 | |
| 14491 | MockWrite data_writes[] = { |
| 14492 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14493 | }; |
| 14494 | MockRead data_reads[] = { |
| 14495 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14496 | }; |
| 14497 | |
| 14498 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14499 | data_writes, arraysize(data_writes)); |
| 14500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14501 | |
| 14502 | TestCompletionCallback callback; |
| 14503 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14504 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14506 | |
| 14507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14508 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14509 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14510 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14511 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14512 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14513 | } |
| 14514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14515 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14516 | HttpRequestInfo request; |
| 14517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14518 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14519 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14521 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14522 | |
| 14523 | MockWrite data_writes[] = { |
| 14524 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14525 | }; |
| 14526 | MockRead data_reads[] = { |
| 14527 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14528 | }; |
| 14529 | |
| 14530 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14531 | data_writes, arraysize(data_writes)); |
| 14532 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14533 | |
| 14534 | TestCompletionCallback callback; |
| 14535 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14536 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14538 | |
| 14539 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14540 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14541 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14542 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14543 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14544 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14545 | } |
| 14546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14547 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14548 | HttpRequestInfo request; |
| 14549 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14550 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14554 | |
| 14555 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14556 | MockWrite( |
| 14557 | "GET / HTTP/1.1\r\n" |
| 14558 | "Host: www.example.org\r\n" |
| 14559 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14560 | }; |
| 14561 | MockRead data_reads[] = { |
| 14562 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14563 | }; |
| 14564 | |
| 14565 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14566 | data_writes, arraysize(data_writes)); |
| 14567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14568 | |
| 14569 | TestCompletionCallback callback; |
| 14570 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14571 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14573 | |
| 14574 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14575 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14576 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14577 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14578 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14579 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14580 | } |
| 14581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14582 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14583 | HttpRequestInfo request; |
| 14584 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14585 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14589 | |
| 14590 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14591 | MockWrite( |
| 14592 | "GET / HTTP/1.1\r\n" |
| 14593 | "Host: www.example.org\r\n" |
| 14594 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14595 | }; |
| 14596 | MockRead data_reads[] = { |
| 14597 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14598 | }; |
| 14599 | |
| 14600 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14601 | data_writes, arraysize(data_writes)); |
| 14602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14603 | |
| 14604 | TestCompletionCallback callback; |
| 14605 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14606 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14607 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14608 | |
| 14609 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14610 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14611 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14612 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14613 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14614 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14615 | } |
| 14616 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14617 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14618 | HttpRequestInfo request; |
| 14619 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14620 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14621 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14622 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14623 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14624 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14625 | |
| 14626 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14627 | MockWrite( |
| 14628 | "GET / HTTP/1.1\r\n" |
| 14629 | "Host: www.example.org\r\n" |
| 14630 | "Connection: keep-alive\r\n" |
| 14631 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14632 | }; |
| 14633 | MockRead data_reads[] = { |
| 14634 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14635 | "Content-Length: 5\r\n\r\n" |
| 14636 | "hello"), |
| 14637 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14638 | }; |
| 14639 | |
| 14640 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14641 | data_writes, arraysize(data_writes)); |
| 14642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14643 | |
| 14644 | TestCompletionCallback callback; |
| 14645 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14646 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14648 | |
| 14649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14651 | |
| 14652 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14653 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14654 | std::string foo; |
| 14655 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14656 | EXPECT_EQ("bar", foo); |
| 14657 | } |
| 14658 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14659 | namespace { |
| 14660 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14661 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14662 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14663 | public base::SupportsWeakPtr<FakeStream> { |
| 14664 | public: |
| 14665 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14666 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14667 | |
| 14668 | RequestPriority priority() const { return priority_; } |
| 14669 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14670 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14671 | RequestPriority priority, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14672 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14673 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14674 | return ERR_IO_PENDING; |
| 14675 | } |
| 14676 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14677 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14678 | HttpResponseInfo* response, |
| 14679 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14680 | ADD_FAILURE(); |
| 14681 | return ERR_UNEXPECTED; |
| 14682 | } |
| 14683 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14684 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14685 | ADD_FAILURE(); |
| 14686 | return ERR_UNEXPECTED; |
| 14687 | } |
| 14688 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14689 | int ReadResponseBody(IOBuffer* buf, |
| 14690 | int buf_len, |
| 14691 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14692 | ADD_FAILURE(); |
| 14693 | return ERR_UNEXPECTED; |
| 14694 | } |
| 14695 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14696 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14697 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14698 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14699 | ADD_FAILURE(); |
| 14700 | return false; |
| 14701 | } |
| 14702 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14703 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14704 | ADD_FAILURE(); |
| 14705 | return false; |
| 14706 | } |
| 14707 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14708 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14709 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14710 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14711 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14712 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14713 | ADD_FAILURE(); |
| 14714 | return 0; |
| 14715 | } |
| 14716 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14717 | int64_t GetTotalSentBytes() const override { |
| 14718 | ADD_FAILURE(); |
| 14719 | return 0; |
| 14720 | } |
| 14721 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14722 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14723 | ADD_FAILURE(); |
| 14724 | return false; |
| 14725 | } |
| 14726 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14727 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14728 | |
| 14729 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14730 | ADD_FAILURE(); |
| 14731 | } |
| 14732 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14733 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14734 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 14735 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 14736 | TokenBindingType tb_type, |
| 14737 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14738 | ADD_FAILURE(); |
| 14739 | return ERR_NOT_IMPLEMENTED; |
| 14740 | } |
| 14741 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14742 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14743 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14744 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14745 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14746 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14747 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14748 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14749 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14750 | private: |
| 14751 | RequestPriority priority_; |
| 14752 | |
| 14753 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14754 | }; |
| 14755 | |
| 14756 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14757 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14758 | class FakeStreamRequest : public HttpStreamRequest, |
| 14759 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14760 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14761 | FakeStreamRequest(RequestPriority priority, |
| 14762 | HttpStreamRequest::Delegate* delegate) |
| 14763 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14764 | delegate_(delegate), |
| 14765 | websocket_stream_create_helper_(NULL) {} |
| 14766 | |
| 14767 | FakeStreamRequest(RequestPriority priority, |
| 14768 | HttpStreamRequest::Delegate* delegate, |
| 14769 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14770 | : priority_(priority), |
| 14771 | delegate_(delegate), |
| 14772 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14773 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14774 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14775 | |
| 14776 | RequestPriority priority() const { return priority_; } |
| 14777 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14778 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14779 | websocket_stream_create_helper() const { |
| 14780 | return websocket_stream_create_helper_; |
| 14781 | } |
| 14782 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14783 | // Create a new FakeStream and pass it to the request's |
| 14784 | // delegate. Returns a weak pointer to the FakeStream. |
| 14785 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14786 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14787 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14788 | // immediately delete |fake_stream|. |
| 14789 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14790 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14791 | return weak_stream; |
| 14792 | } |
| 14793 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14794 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14795 | ADD_FAILURE(); |
| 14796 | return ERR_UNEXPECTED; |
| 14797 | } |
| 14798 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14799 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14800 | ADD_FAILURE(); |
| 14801 | return LoadState(); |
| 14802 | } |
| 14803 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14804 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14805 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14806 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14807 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 14808 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14809 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14810 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14811 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14812 | const ConnectionAttempts& connection_attempts() const override { |
| 14813 | static ConnectionAttempts no_attempts; |
| 14814 | return no_attempts; |
| 14815 | } |
| 14816 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14817 | private: |
| 14818 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14819 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14820 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14821 | |
| 14822 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14823 | }; |
| 14824 | |
| 14825 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14826 | class FakeStreamFactory : public HttpStreamFactory { |
| 14827 | public: |
| 14828 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14829 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14830 | |
| 14831 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14832 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14833 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14834 | return last_stream_request_; |
| 14835 | } |
| 14836 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14837 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14838 | RequestPriority priority, |
| 14839 | const SSLConfig& server_ssl_config, |
| 14840 | const SSLConfig& proxy_ssl_config, |
| 14841 | HttpStreamRequest::Delegate* delegate, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14842 | const NetLogWithSource& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14843 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14844 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14845 | return fake_request; |
| 14846 | } |
| 14847 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14848 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14849 | const HttpRequestInfo& info, |
| 14850 | RequestPriority priority, |
| 14851 | const SSLConfig& server_ssl_config, |
| 14852 | const SSLConfig& proxy_ssl_config, |
| 14853 | HttpStreamRequest::Delegate* delegate, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14854 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14855 | NOTREACHED(); |
| 14856 | return nullptr; |
| 14857 | } |
| 14858 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14859 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14860 | const HttpRequestInfo& info, |
| 14861 | RequestPriority priority, |
| 14862 | const SSLConfig& server_ssl_config, |
| 14863 | const SSLConfig& proxy_ssl_config, |
| 14864 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14865 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14866 | const NetLogWithSource& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14867 | FakeStreamRequest* fake_request = |
| 14868 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14869 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14870 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14871 | } |
| 14872 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14873 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14874 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14875 | ADD_FAILURE(); |
| 14876 | } |
| 14877 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14878 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14879 | ADD_FAILURE(); |
| 14880 | return NULL; |
| 14881 | } |
| 14882 | |
| 14883 | private: |
| 14884 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14885 | |
| 14886 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14887 | }; |
| 14888 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14889 | // TODO(ricea): Maybe unify this with the one in |
| 14890 | // url_request_http_job_unittest.cc ? |
| 14891 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14892 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14893 | FakeWebSocketBasicHandshakeStream( |
| 14894 | std::unique_ptr<ClientSocketHandle> connection, |
| 14895 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 14896 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14897 | |
| 14898 | // Fake implementation of HttpStreamBase methods. |
| 14899 | // This ends up being quite "real" because this object has to really send data |
| 14900 | // on the mock socket. It might be easier to use the real implementation, but |
| 14901 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14902 | // difficult. |
| 14903 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14904 | RequestPriority priority, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14905 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14906 | const CompletionCallback& callback) override { |
| 14907 | state_.Initialize(request_info, priority, net_log, callback); |
| 14908 | return OK; |
| 14909 | } |
| 14910 | |
| 14911 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14912 | HttpResponseInfo* response, |
| 14913 | const CompletionCallback& callback) override { |
| 14914 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14915 | response, callback); |
| 14916 | } |
| 14917 | |
| 14918 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14919 | return parser()->ReadResponseHeaders(callback); |
| 14920 | } |
| 14921 | |
| 14922 | int ReadResponseBody(IOBuffer* buf, |
| 14923 | int buf_len, |
| 14924 | const CompletionCallback& callback) override { |
| 14925 | NOTREACHED(); |
| 14926 | return ERR_IO_PENDING; |
| 14927 | } |
| 14928 | |
| 14929 | void Close(bool not_reusable) override { |
| 14930 | if (parser()) |
| 14931 | parser()->Close(true); |
| 14932 | } |
| 14933 | |
| 14934 | bool IsResponseBodyComplete() const override { |
| 14935 | NOTREACHED(); |
| 14936 | return false; |
| 14937 | } |
| 14938 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14939 | bool IsConnectionReused() const override { |
| 14940 | NOTREACHED(); |
| 14941 | return false; |
| 14942 | } |
| 14943 | void SetConnectionReused() override { NOTREACHED(); } |
| 14944 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14945 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14946 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14947 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14948 | NOTREACHED(); |
| 14949 | return 0; |
| 14950 | } |
| 14951 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14952 | int64_t GetTotalSentBytes() const override { |
| 14953 | NOTREACHED(); |
| 14954 | return 0; |
| 14955 | } |
| 14956 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14957 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14958 | NOTREACHED(); |
| 14959 | return false; |
| 14960 | } |
| 14961 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14962 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14963 | |
| 14964 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14965 | NOTREACHED(); |
| 14966 | } |
| 14967 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14968 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14969 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 14970 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 14971 | TokenBindingType tb_type, |
| 14972 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14973 | ADD_FAILURE(); |
| 14974 | return ERR_NOT_IMPLEMENTED; |
| 14975 | } |
| 14976 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14977 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14978 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14979 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14980 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14981 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14982 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14983 | HttpStream* RenewStreamForAuth() override { |
| 14984 | NOTREACHED(); |
| 14985 | return nullptr; |
| 14986 | } |
| 14987 | |
| 14988 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14989 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14990 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14991 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14992 | } |
| 14993 | |
| 14994 | private: |
| 14995 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14996 | HttpBasicState state_; |
| 14997 | |
| 14998 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14999 | }; |
| 15000 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15001 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15002 | // worth doing. |
| 15003 | class FakeWebSocketStreamCreateHelper : |
| 15004 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15005 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15006 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15007 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15008 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15009 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15010 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15011 | } |
| 15012 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15013 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15014 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15015 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15016 | NOTREACHED(); |
| 15017 | return NULL; |
| 15018 | }; |
| 15019 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15020 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15022 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15023 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15024 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15025 | } |
| 15026 | }; |
| 15027 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15028 | } // namespace |
| 15029 | |
| 15030 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15031 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15032 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15034 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15035 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15036 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15037 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15038 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15039 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15040 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15041 | |
| 15042 | HttpRequestInfo request; |
| 15043 | TestCompletionCallback callback; |
| 15044 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15045 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15046 | |
| 15047 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15048 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15049 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15050 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15051 | } |
| 15052 | |
| 15053 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15054 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15055 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15057 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15058 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15059 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15060 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15061 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15062 | |
| 15063 | HttpRequestInfo request; |
| 15064 | TestCompletionCallback callback; |
| 15065 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15066 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15067 | |
| 15068 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15069 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15070 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15071 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15072 | |
| 15073 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15074 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15075 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15076 | } |
| 15077 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15078 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15079 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15080 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15082 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15083 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15084 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15085 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15086 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15087 | |
| 15088 | HttpRequestInfo request; |
| 15089 | TestCompletionCallback callback; |
| 15090 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15091 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15092 | |
| 15093 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15094 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15095 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15096 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15097 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15098 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15099 | |
| 15100 | trans.SetPriority(LOWEST); |
| 15101 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15102 | } |
| 15103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15104 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15105 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15106 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15107 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15108 | std::string test_cases[] = {"ws://www.example.org/", |
| 15109 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15110 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15111 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15112 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15113 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15114 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15115 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15116 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15117 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15118 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15119 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15120 | &websocket_stream_create_helper); |
| 15121 | |
| 15122 | HttpRequestInfo request; |
| 15123 | TestCompletionCallback callback; |
| 15124 | request.method = "GET"; |
| 15125 | request.url = GURL(test_cases[i]); |
| 15126 | |
| 15127 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15128 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15129 | |
| 15130 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15131 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15132 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15133 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15134 | fake_request->websocket_stream_create_helper()); |
| 15135 | } |
| 15136 | } |
| 15137 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15138 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15139 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15140 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15141 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15142 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15143 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15144 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15145 | |
| 15146 | // Set up SSL request. |
| 15147 | |
| 15148 | HttpRequestInfo ssl_request; |
| 15149 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15150 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15151 | |
| 15152 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15153 | MockWrite( |
| 15154 | "GET / HTTP/1.1\r\n" |
| 15155 | "Host: www.example.org\r\n" |
| 15156 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15157 | }; |
| 15158 | MockRead ssl_reads[] = { |
| 15159 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15160 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15161 | MockRead("hello world"), |
| 15162 | MockRead(SYNCHRONOUS, OK), |
| 15163 | }; |
| 15164 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15165 | ssl_writes, arraysize(ssl_writes)); |
| 15166 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15167 | |
| 15168 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15170 | |
| 15171 | // Set up HTTP request. |
| 15172 | |
| 15173 | HttpRequestInfo http_request; |
| 15174 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15175 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15176 | |
| 15177 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15178 | MockWrite( |
| 15179 | "GET / HTTP/1.1\r\n" |
| 15180 | "Host: www.example.org\r\n" |
| 15181 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15182 | }; |
| 15183 | MockRead http_reads[] = { |
| 15184 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15185 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15186 | MockRead("falafel"), |
| 15187 | MockRead(SYNCHRONOUS, OK), |
| 15188 | }; |
| 15189 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15190 | http_writes, arraysize(http_writes)); |
| 15191 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15194 | |
| 15195 | // Start the SSL request. |
| 15196 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15197 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15198 | ASSERT_EQ(ERR_IO_PENDING, |
| 15199 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15200 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15201 | |
| 15202 | // Start the HTTP request. Pool should stall. |
| 15203 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15204 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15205 | ASSERT_EQ(ERR_IO_PENDING, |
| 15206 | http_trans.Start(&http_request, http_callback.callback(), |
| 15207 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15208 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15209 | |
| 15210 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15211 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15212 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15213 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15214 | EXPECT_EQ("hello world", response_data); |
| 15215 | |
| 15216 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15217 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15218 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15219 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15220 | |
| 15221 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15222 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15223 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15224 | EXPECT_EQ("falafel", response_data); |
| 15225 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15226 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15227 | } |
| 15228 | |
| 15229 | // Tests that when a SSL connection is established but there's no corresponding |
| 15230 | // request that needs it, the new socket is closed if the transport socket pool |
| 15231 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15232 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15233 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15234 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15235 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15236 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15237 | |
| 15238 | // Set up an ssl request. |
| 15239 | |
| 15240 | HttpRequestInfo ssl_request; |
| 15241 | ssl_request.method = "GET"; |
| 15242 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15243 | |
| 15244 | // No data will be sent on the SSL socket. |
| 15245 | StaticSocketDataProvider ssl_data; |
| 15246 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15247 | |
| 15248 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15250 | |
| 15251 | // Set up HTTP request. |
| 15252 | |
| 15253 | HttpRequestInfo http_request; |
| 15254 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15255 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15256 | |
| 15257 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15258 | MockWrite( |
| 15259 | "GET / HTTP/1.1\r\n" |
| 15260 | "Host: www.example.org\r\n" |
| 15261 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15262 | }; |
| 15263 | MockRead http_reads[] = { |
| 15264 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15265 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15266 | MockRead("falafel"), |
| 15267 | MockRead(SYNCHRONOUS, OK), |
| 15268 | }; |
| 15269 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15270 | http_writes, arraysize(http_writes)); |
| 15271 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15272 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15274 | |
| 15275 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15276 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15277 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15278 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15279 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15280 | |
| 15281 | // Start the HTTP request. Pool should stall. |
| 15282 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15283 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15284 | ASSERT_EQ(ERR_IO_PENDING, |
| 15285 | http_trans.Start(&http_request, http_callback.callback(), |
| 15286 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15287 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15288 | |
| 15289 | // The SSL connection will automatically be closed once the connection is |
| 15290 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15291 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15292 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15293 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15294 | EXPECT_EQ("falafel", response_data); |
| 15295 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15296 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15297 | } |
| 15298 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15299 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15300 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15301 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15302 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15303 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15304 | |
| 15305 | HttpRequestInfo request; |
| 15306 | request.method = "POST"; |
| 15307 | request.url = GURL("http://www.foo.com/"); |
| 15308 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15312 | // Send headers successfully, but get an error while sending the body. |
| 15313 | MockWrite data_writes[] = { |
| 15314 | MockWrite("POST / HTTP/1.1\r\n" |
| 15315 | "Host: www.foo.com\r\n" |
| 15316 | "Connection: keep-alive\r\n" |
| 15317 | "Content-Length: 3\r\n\r\n"), |
| 15318 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15319 | }; |
| 15320 | |
| 15321 | MockRead data_reads[] = { |
| 15322 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15323 | MockRead("hello world"), |
| 15324 | MockRead(SYNCHRONOUS, OK), |
| 15325 | }; |
| 15326 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15327 | arraysize(data_writes)); |
| 15328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15329 | |
| 15330 | TestCompletionCallback callback; |
| 15331 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15334 | |
| 15335 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15338 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15339 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15340 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15341 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15342 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15343 | |
| 15344 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15345 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15346 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15347 | EXPECT_EQ("hello world", response_data); |
| 15348 | } |
| 15349 | |
| 15350 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15351 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15352 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15353 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15355 | MockWrite data_writes[] = { |
| 15356 | MockWrite("GET / HTTP/1.1\r\n" |
| 15357 | "Host: www.foo.com\r\n" |
| 15358 | "Connection: keep-alive\r\n\r\n"), |
| 15359 | MockWrite("POST / HTTP/1.1\r\n" |
| 15360 | "Host: www.foo.com\r\n" |
| 15361 | "Connection: keep-alive\r\n" |
| 15362 | "Content-Length: 3\r\n\r\n"), |
| 15363 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15364 | }; |
| 15365 | |
| 15366 | MockRead data_reads[] = { |
| 15367 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15368 | "Content-Length: 14\r\n\r\n"), |
| 15369 | MockRead("first response"), |
| 15370 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15371 | "Content-Length: 15\r\n\r\n"), |
| 15372 | MockRead("second response"), |
| 15373 | MockRead(SYNCHRONOUS, OK), |
| 15374 | }; |
| 15375 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15376 | arraysize(data_writes)); |
| 15377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15378 | |
| 15379 | TestCompletionCallback callback; |
| 15380 | HttpRequestInfo request1; |
| 15381 | request1.method = "GET"; |
| 15382 | request1.url = GURL("http://www.foo.com/"); |
| 15383 | request1.load_flags = 0; |
| 15384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15385 | std::unique_ptr<HttpNetworkTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15387 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15389 | |
| 15390 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15392 | |
| 15393 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15394 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15395 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15396 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15397 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15398 | |
| 15399 | std::string response_data1; |
| 15400 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15401 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15402 | EXPECT_EQ("first response", response_data1); |
| 15403 | // Delete the transaction to release the socket back into the socket pool. |
| 15404 | trans1.reset(); |
| 15405 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15406 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15407 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15408 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15409 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15410 | |
| 15411 | HttpRequestInfo request2; |
| 15412 | request2.method = "POST"; |
| 15413 | request2.url = GURL("http://www.foo.com/"); |
| 15414 | request2.upload_data_stream = &upload_data_stream; |
| 15415 | request2.load_flags = 0; |
| 15416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15417 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15418 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15420 | |
| 15421 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15424 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15425 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15426 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15427 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15428 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15429 | |
| 15430 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15431 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15433 | EXPECT_EQ("second response", response_data2); |
| 15434 | } |
| 15435 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15436 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15437 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15438 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15439 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15440 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15441 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15442 | |
| 15443 | HttpRequestInfo request; |
| 15444 | request.method = "POST"; |
| 15445 | request.url = GURL("http://www.foo.com/"); |
| 15446 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15447 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15450 | // Send headers successfully, but get an error while sending the body. |
| 15451 | MockWrite data_writes[] = { |
| 15452 | MockWrite("POST / HTTP/1.1\r\n" |
| 15453 | "Host: www.foo.com\r\n" |
| 15454 | "Connection: keep-alive\r\n" |
| 15455 | "Content-Length: 3\r\n\r\n" |
| 15456 | "fo"), |
| 15457 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15458 | }; |
| 15459 | |
| 15460 | MockRead data_reads[] = { |
| 15461 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15462 | MockRead("hello world"), |
| 15463 | MockRead(SYNCHRONOUS, OK), |
| 15464 | }; |
| 15465 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15466 | arraysize(data_writes)); |
| 15467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15468 | |
| 15469 | TestCompletionCallback callback; |
| 15470 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15471 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15473 | |
| 15474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15478 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15479 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15480 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15481 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15482 | |
| 15483 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15484 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15486 | EXPECT_EQ("hello world", response_data); |
| 15487 | } |
| 15488 | |
| 15489 | // This tests the more common case than the previous test, where headers and |
| 15490 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15491 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15492 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15493 | |
| 15494 | HttpRequestInfo request; |
| 15495 | request.method = "POST"; |
| 15496 | request.url = GURL("http://www.foo.com/"); |
| 15497 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15501 | // Send headers successfully, but get an error while sending the body. |
| 15502 | MockWrite data_writes[] = { |
| 15503 | MockWrite("POST / HTTP/1.1\r\n" |
| 15504 | "Host: www.foo.com\r\n" |
| 15505 | "Connection: keep-alive\r\n" |
| 15506 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15507 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15508 | }; |
| 15509 | |
| 15510 | MockRead data_reads[] = { |
| 15511 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15512 | MockRead("hello world"), |
| 15513 | MockRead(SYNCHRONOUS, OK), |
| 15514 | }; |
| 15515 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15516 | arraysize(data_writes)); |
| 15517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15518 | |
| 15519 | TestCompletionCallback callback; |
| 15520 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15521 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15522 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15523 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15524 | // they can't be merged with the body in a single send. Not currently |
| 15525 | // necessary since a chunked body is never merged with headers, but this makes |
| 15526 | // the test more future proof. |
| 15527 | base::RunLoop().RunUntilIdle(); |
| 15528 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15529 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15530 | |
| 15531 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15532 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15535 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15536 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15537 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15538 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15539 | |
| 15540 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15541 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15542 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15543 | EXPECT_EQ("hello world", response_data); |
| 15544 | } |
| 15545 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15546 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15547 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15548 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15549 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15550 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15551 | |
| 15552 | HttpRequestInfo request; |
| 15553 | request.method = "POST"; |
| 15554 | request.url = GURL("http://www.foo.com/"); |
| 15555 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15559 | |
| 15560 | MockWrite data_writes[] = { |
| 15561 | MockWrite("POST / HTTP/1.1\r\n" |
| 15562 | "Host: www.foo.com\r\n" |
| 15563 | "Connection: keep-alive\r\n" |
| 15564 | "Content-Length: 3\r\n\r\n"), |
| 15565 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15566 | }; |
| 15567 | |
| 15568 | MockRead data_reads[] = { |
| 15569 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15570 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15571 | MockRead("hello world"), |
| 15572 | MockRead(SYNCHRONOUS, OK), |
| 15573 | }; |
| 15574 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15575 | arraysize(data_writes)); |
| 15576 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15577 | |
| 15578 | TestCompletionCallback callback; |
| 15579 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15580 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15582 | |
| 15583 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15584 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15586 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15587 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15588 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15589 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15590 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15591 | |
| 15592 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15593 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15594 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15595 | EXPECT_EQ("hello world", response_data); |
| 15596 | } |
| 15597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15598 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15599 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15600 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15601 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15602 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15603 | |
| 15604 | HttpRequestInfo request; |
| 15605 | request.method = "POST"; |
| 15606 | request.url = GURL("http://www.foo.com/"); |
| 15607 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15608 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15611 | // Send headers successfully, but get an error while sending the body. |
| 15612 | MockWrite data_writes[] = { |
| 15613 | MockWrite("POST / HTTP/1.1\r\n" |
| 15614 | "Host: www.foo.com\r\n" |
| 15615 | "Connection: keep-alive\r\n" |
| 15616 | "Content-Length: 3\r\n\r\n"), |
| 15617 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15618 | }; |
| 15619 | |
| 15620 | MockRead data_reads[] = { |
| 15621 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15622 | MockRead("hello world"), |
| 15623 | MockRead(SYNCHRONOUS, OK), |
| 15624 | }; |
| 15625 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15626 | arraysize(data_writes)); |
| 15627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15628 | |
| 15629 | TestCompletionCallback callback; |
| 15630 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15631 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15633 | |
| 15634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15635 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15636 | } |
| 15637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15638 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15639 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15640 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15641 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15642 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15643 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15644 | |
| 15645 | HttpRequestInfo request; |
| 15646 | request.method = "POST"; |
| 15647 | request.url = GURL("http://www.foo.com/"); |
| 15648 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15652 | // Send headers successfully, but get an error while sending the body. |
| 15653 | MockWrite data_writes[] = { |
| 15654 | MockWrite("POST / HTTP/1.1\r\n" |
| 15655 | "Host: www.foo.com\r\n" |
| 15656 | "Connection: keep-alive\r\n" |
| 15657 | "Content-Length: 3\r\n\r\n"), |
| 15658 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15659 | }; |
| 15660 | |
| 15661 | MockRead data_reads[] = { |
| 15662 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15663 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15664 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15665 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15666 | MockRead(SYNCHRONOUS, OK), |
| 15667 | }; |
| 15668 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15669 | arraysize(data_writes)); |
| 15670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15671 | |
| 15672 | TestCompletionCallback callback; |
| 15673 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15674 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15676 | |
| 15677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15678 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15679 | } |
| 15680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15681 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15682 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15683 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15684 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15685 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15686 | |
| 15687 | HttpRequestInfo request; |
| 15688 | request.method = "POST"; |
| 15689 | request.url = GURL("http://www.foo.com/"); |
| 15690 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15694 | // Send headers successfully, but get an error while sending the body. |
| 15695 | MockWrite data_writes[] = { |
| 15696 | MockWrite("POST / HTTP/1.1\r\n" |
| 15697 | "Host: www.foo.com\r\n" |
| 15698 | "Connection: keep-alive\r\n" |
| 15699 | "Content-Length: 3\r\n\r\n"), |
| 15700 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15701 | }; |
| 15702 | |
| 15703 | MockRead data_reads[] = { |
| 15704 | MockRead("HTTP 0.9 rocks!"), |
| 15705 | MockRead(SYNCHRONOUS, OK), |
| 15706 | }; |
| 15707 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15708 | arraysize(data_writes)); |
| 15709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15710 | |
| 15711 | TestCompletionCallback callback; |
| 15712 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15715 | |
| 15716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15717 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15718 | } |
| 15719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15720 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15721 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15722 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15723 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15724 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15725 | |
| 15726 | HttpRequestInfo request; |
| 15727 | request.method = "POST"; |
| 15728 | request.url = GURL("http://www.foo.com/"); |
| 15729 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15733 | // Send headers successfully, but get an error while sending the body. |
| 15734 | MockWrite data_writes[] = { |
| 15735 | MockWrite("POST / HTTP/1.1\r\n" |
| 15736 | "Host: www.foo.com\r\n" |
| 15737 | "Connection: keep-alive\r\n" |
| 15738 | "Content-Length: 3\r\n\r\n"), |
| 15739 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15740 | }; |
| 15741 | |
| 15742 | MockRead data_reads[] = { |
| 15743 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15744 | MockRead(SYNCHRONOUS, OK), |
| 15745 | }; |
| 15746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15747 | arraysize(data_writes)); |
| 15748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15749 | |
| 15750 | TestCompletionCallback callback; |
| 15751 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15754 | |
| 15755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15756 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15757 | } |
| 15758 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15759 | // Verify that proxy headers are not sent to the destination server when |
| 15760 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15761 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15762 | HttpRequestInfo request; |
| 15763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15764 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15765 | AddWebSocketHeaders(&request.extra_headers); |
| 15766 | |
| 15767 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15768 | session_deps_.proxy_service = |
| 15769 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15770 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15772 | |
| 15773 | // Since a proxy is configured, try to establish a tunnel. |
| 15774 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15775 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15776 | "Host: www.example.org:443\r\n" |
| 15777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15778 | |
| 15779 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15780 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15781 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15782 | "Host: www.example.org:443\r\n" |
| 15783 | "Proxy-Connection: keep-alive\r\n" |
| 15784 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15785 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15786 | MockWrite("GET / HTTP/1.1\r\n" |
| 15787 | "Host: www.example.org\r\n" |
| 15788 | "Connection: Upgrade\r\n" |
| 15789 | "Upgrade: websocket\r\n" |
| 15790 | "Origin: http://www.example.org\r\n" |
| 15791 | "Sec-WebSocket-Version: 13\r\n" |
| 15792 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15793 | }; |
| 15794 | |
| 15795 | // The proxy responds to the connect with a 407, using a persistent |
| 15796 | // connection. |
| 15797 | MockRead data_reads[] = { |
| 15798 | // No credentials. |
| 15799 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15800 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15801 | MockRead("Content-Length: 0\r\n"), |
| 15802 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15803 | |
| 15804 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15805 | |
| 15806 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15807 | MockRead("Upgrade: websocket\r\n"), |
| 15808 | MockRead("Connection: Upgrade\r\n"), |
| 15809 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15810 | }; |
| 15811 | |
| 15812 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15813 | arraysize(data_writes)); |
| 15814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15815 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15816 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15818 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15819 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15820 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15821 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15822 | &websocket_stream_create_helper); |
| 15823 | |
| 15824 | { |
| 15825 | TestCompletionCallback callback; |
| 15826 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15827 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15829 | |
| 15830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15831 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15832 | } |
| 15833 | |
| 15834 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15835 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15836 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15837 | EXPECT_EQ(407, response->headers->response_code()); |
| 15838 | |
| 15839 | { |
| 15840 | TestCompletionCallback callback; |
| 15841 | |
| 15842 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15843 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15845 | |
| 15846 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15847 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15848 | } |
| 15849 | |
| 15850 | response = trans->GetResponseInfo(); |
| 15851 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15852 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15853 | |
| 15854 | EXPECT_EQ(101, response->headers->response_code()); |
| 15855 | |
| 15856 | trans.reset(); |
| 15857 | session->CloseAllConnections(); |
| 15858 | } |
| 15859 | |
| 15860 | // Verify that proxy headers are not sent to the destination server when |
| 15861 | // establishing a tunnel for an insecure WebSocket connection. |
| 15862 | // This requires the authentication info to be injected into the auth cache |
| 15863 | // due to crbug.com/395064 |
| 15864 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15865 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15866 | HttpRequestInfo request; |
| 15867 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15868 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15869 | AddWebSocketHeaders(&request.extra_headers); |
| 15870 | |
| 15871 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15872 | session_deps_.proxy_service = |
| 15873 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15876 | |
| 15877 | MockWrite data_writes[] = { |
| 15878 | // Try to establish a tunnel for the WebSocket connection, with |
| 15879 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15880 | // they cannot and will not use the same TCP/IP connection as the |
| 15881 | // preflight HTTP request. |
| 15882 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15883 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15884 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15885 | "Proxy-Connection: keep-alive\r\n" |
| 15886 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15887 | |
| 15888 | MockWrite( |
| 15889 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15890 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15891 | "Connection: Upgrade\r\n" |
| 15892 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15893 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15894 | "Sec-WebSocket-Version: 13\r\n" |
| 15895 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15896 | }; |
| 15897 | |
| 15898 | MockRead data_reads[] = { |
| 15899 | // HTTP CONNECT with credentials. |
| 15900 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15901 | |
| 15902 | // WebSocket connection established inside tunnel. |
| 15903 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15904 | MockRead("Upgrade: websocket\r\n"), |
| 15905 | MockRead("Connection: Upgrade\r\n"), |
| 15906 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15907 | }; |
| 15908 | |
| 15909 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15910 | arraysize(data_writes)); |
| 15911 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15912 | |
| 15913 | session->http_auth_cache()->Add( |
| 15914 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15915 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15917 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15919 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15920 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15921 | &websocket_stream_create_helper); |
| 15922 | |
| 15923 | TestCompletionCallback callback; |
| 15924 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15925 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15927 | |
| 15928 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15929 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15930 | |
| 15931 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15932 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15933 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15934 | |
| 15935 | EXPECT_EQ(101, response->headers->response_code()); |
| 15936 | |
| 15937 | trans.reset(); |
| 15938 | session->CloseAllConnections(); |
| 15939 | } |
| 15940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15941 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15942 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15943 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15944 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15945 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15946 | |
| 15947 | HttpRequestInfo request; |
| 15948 | request.method = "POST"; |
| 15949 | request.url = GURL("http://www.foo.com/"); |
| 15950 | request.upload_data_stream = &upload_data_stream; |
| 15951 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15953 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15954 | MockWrite data_writes[] = { |
| 15955 | MockWrite("POST / HTTP/1.1\r\n" |
| 15956 | "Host: www.foo.com\r\n" |
| 15957 | "Connection: keep-alive\r\n" |
| 15958 | "Content-Length: 3\r\n\r\n"), |
| 15959 | MockWrite("foo"), |
| 15960 | }; |
| 15961 | |
| 15962 | MockRead data_reads[] = { |
| 15963 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15964 | MockRead(SYNCHRONOUS, OK), |
| 15965 | }; |
| 15966 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15967 | arraysize(data_writes)); |
| 15968 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15969 | |
| 15970 | TestCompletionCallback callback; |
| 15971 | |
| 15972 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15973 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15974 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15975 | |
| 15976 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15977 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15978 | |
| 15979 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15980 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15981 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15982 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15983 | } |
| 15984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15985 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15986 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15987 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15988 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15989 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15990 | |
| 15991 | HttpRequestInfo request; |
| 15992 | request.method = "POST"; |
| 15993 | request.url = GURL("http://www.foo.com/"); |
| 15994 | request.upload_data_stream = &upload_data_stream; |
| 15995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15998 | MockWrite data_writes[] = { |
| 15999 | MockWrite("POST / HTTP/1.1\r\n" |
| 16000 | "Host: www.foo.com\r\n" |
| 16001 | "Connection: keep-alive\r\n" |
| 16002 | "Content-Length: 3\r\n\r\n"), |
| 16003 | MockWrite("foo"), |
| 16004 | }; |
| 16005 | |
| 16006 | MockRead data_reads[] = { |
| 16007 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16008 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16009 | MockRead(SYNCHRONOUS, OK), |
| 16010 | }; |
| 16011 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16012 | arraysize(data_writes)); |
| 16013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16014 | |
| 16015 | TestCompletionCallback callback; |
| 16016 | |
| 16017 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16018 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16019 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16020 | |
| 16021 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16022 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16023 | |
| 16024 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16025 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16026 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16027 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16028 | } |
| 16029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16030 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16031 | ChunkedUploadDataStream upload_data_stream(0); |
| 16032 | |
| 16033 | HttpRequestInfo request; |
| 16034 | request.method = "POST"; |
| 16035 | request.url = GURL("http://www.foo.com/"); |
| 16036 | request.upload_data_stream = &upload_data_stream; |
| 16037 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16039 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16040 | // Send headers successfully, but get an error while sending the body. |
| 16041 | MockWrite data_writes[] = { |
| 16042 | MockWrite("POST / HTTP/1.1\r\n" |
| 16043 | "Host: www.foo.com\r\n" |
| 16044 | "Connection: keep-alive\r\n" |
| 16045 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16046 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16047 | }; |
| 16048 | |
| 16049 | MockRead data_reads[] = { |
| 16050 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16051 | MockRead(SYNCHRONOUS, OK), |
| 16052 | }; |
| 16053 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16054 | arraysize(data_writes)); |
| 16055 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16056 | |
| 16057 | TestCompletionCallback callback; |
| 16058 | |
| 16059 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16060 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16061 | |
| 16062 | base::RunLoop().RunUntilIdle(); |
| 16063 | upload_data_stream.AppendData("f", 1, false); |
| 16064 | |
| 16065 | base::RunLoop().RunUntilIdle(); |
| 16066 | upload_data_stream.AppendData("oo", 2, true); |
| 16067 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16068 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16069 | |
| 16070 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16071 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16072 | |
| 16073 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16074 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16075 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16076 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16077 | } |
| 16078 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame^] | 16079 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16080 | // the unthrottled state are not blocked. |
| 16081 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16082 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16083 | std::unique_ptr<HttpNetworkSession> session( |
| 16084 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16085 | |
| 16086 | // Send a simple request and make sure it goes through. |
| 16087 | HttpRequestInfo request; |
| 16088 | request.method = "GET"; |
| 16089 | request.url = GURL("http://www.example.org/"); |
| 16090 | |
| 16091 | std::unique_ptr<HttpTransaction> trans( |
| 16092 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16093 | |
| 16094 | MockWrite data_writes[] = { |
| 16095 | MockWrite("GET / HTTP/1.1\r\n" |
| 16096 | "Host: www.example.org\r\n" |
| 16097 | "Connection: keep-alive\r\n\r\n"), |
| 16098 | }; |
| 16099 | MockRead data_reads[] = { |
| 16100 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16101 | MockRead(SYNCHRONOUS, OK), |
| 16102 | }; |
| 16103 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16104 | arraysize(data_writes)); |
| 16105 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16106 | |
| 16107 | TestCompletionCallback callback; |
| 16108 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16109 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16110 | } |
| 16111 | |
| 16112 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16113 | // when the throttle is unblocked. |
| 16114 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16115 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16116 | std::unique_ptr<HttpNetworkSession> session( |
| 16117 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16118 | |
| 16119 | // Send a simple request and make sure it goes through. |
| 16120 | HttpRequestInfo request; |
| 16121 | request.method = "GET"; |
| 16122 | request.url = GURL("http://www.example.org/"); |
| 16123 | |
| 16124 | MockWrite data_writes[] = { |
| 16125 | MockWrite("GET / HTTP/1.1\r\n" |
| 16126 | "Host: www.example.org\r\n" |
| 16127 | "Connection: keep-alive\r\n\r\n"), |
| 16128 | }; |
| 16129 | MockRead data_reads[] = { |
| 16130 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16131 | MockRead(SYNCHRONOUS, OK), |
| 16132 | }; |
| 16133 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16134 | arraysize(data_writes)); |
| 16135 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16136 | |
| 16137 | // Start a request that will be throttled at start; confirm it |
| 16138 | // doesn't complete. |
| 16139 | throttler->set_throttle_new_requests(true); |
| 16140 | std::unique_ptr<HttpTransaction> trans( |
| 16141 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16142 | |
| 16143 | TestCompletionCallback callback; |
| 16144 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16145 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16146 | |
| 16147 | base::RunLoop().RunUntilIdle(); |
| 16148 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16149 | EXPECT_FALSE(callback.have_result()); |
| 16150 | |
| 16151 | // Confirm the request goes on to complete when unthrottled. |
| 16152 | throttler->UnthrottleAllRequests(); |
| 16153 | base::RunLoop().RunUntilIdle(); |
| 16154 | ASSERT_TRUE(callback.have_result()); |
| 16155 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16156 | } |
| 16157 | |
| 16158 | // Destroy a request while it's throttled. |
| 16159 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16160 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16161 | std::unique_ptr<HttpNetworkSession> session( |
| 16162 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16163 | |
| 16164 | // Send a simple request and make sure it goes through. |
| 16165 | HttpRequestInfo request; |
| 16166 | request.method = "GET"; |
| 16167 | request.url = GURL("http://www.example.org/"); |
| 16168 | |
| 16169 | MockWrite data_writes[] = { |
| 16170 | MockWrite("GET / HTTP/1.1\r\n" |
| 16171 | "Host: www.example.org\r\n" |
| 16172 | "Connection: keep-alive\r\n\r\n"), |
| 16173 | }; |
| 16174 | MockRead data_reads[] = { |
| 16175 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16176 | MockRead(SYNCHRONOUS, OK), |
| 16177 | }; |
| 16178 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16179 | arraysize(data_writes)); |
| 16180 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16181 | |
| 16182 | // Start a request that will be throttled at start; confirm it |
| 16183 | // doesn't complete. |
| 16184 | throttler->set_throttle_new_requests(true); |
| 16185 | std::unique_ptr<HttpTransaction> trans( |
| 16186 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16187 | |
| 16188 | TestCompletionCallback callback; |
| 16189 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16191 | |
| 16192 | base::RunLoop().RunUntilIdle(); |
| 16193 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16194 | EXPECT_FALSE(callback.have_result()); |
| 16195 | |
| 16196 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16197 | trans.reset(); |
| 16198 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16199 | } |
| 16200 | |
| 16201 | // Confirm the throttler receives SetPriority calls. |
| 16202 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16203 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16204 | std::unique_ptr<HttpNetworkSession> session( |
| 16205 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16206 | |
| 16207 | // Send a simple request and make sure it goes through. |
| 16208 | HttpRequestInfo request; |
| 16209 | request.method = "GET"; |
| 16210 | request.url = GURL("http://www.example.org/"); |
| 16211 | |
| 16212 | MockWrite data_writes[] = { |
| 16213 | MockWrite("GET / HTTP/1.1\r\n" |
| 16214 | "Host: www.example.org\r\n" |
| 16215 | "Connection: keep-alive\r\n\r\n"), |
| 16216 | }; |
| 16217 | MockRead data_reads[] = { |
| 16218 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16219 | MockRead(SYNCHRONOUS, OK), |
| 16220 | }; |
| 16221 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16222 | arraysize(data_writes)); |
| 16223 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16224 | |
| 16225 | throttler->set_throttle_new_requests(true); |
| 16226 | std::unique_ptr<HttpTransaction> trans( |
| 16227 | new HttpNetworkTransaction(IDLE, session.get())); |
| 16228 | // Start the transaction to associate a throttle with it. |
| 16229 | TestCompletionCallback callback; |
| 16230 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16232 | |
| 16233 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16234 | trans->SetPriority(LOW); |
| 16235 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16236 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16237 | |
| 16238 | throttler->UnthrottleAllRequests(); |
| 16239 | base::RunLoop().RunUntilIdle(); |
| 16240 | ASSERT_TRUE(callback.have_result()); |
| 16241 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16242 | } |
| 16243 | |
| 16244 | // Confirm that unthrottling from a SetPriority call by the |
| 16245 | // throttler works properly. |
| 16246 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16247 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16248 | std::unique_ptr<HttpNetworkSession> session( |
| 16249 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16250 | |
| 16251 | // Send a simple request and make sure it goes through. |
| 16252 | HttpRequestInfo request; |
| 16253 | request.method = "GET"; |
| 16254 | request.url = GURL("http://www.example.org/"); |
| 16255 | |
| 16256 | MockWrite data_writes[] = { |
| 16257 | MockWrite("GET / HTTP/1.1\r\n" |
| 16258 | "Host: www.example.org\r\n" |
| 16259 | "Connection: keep-alive\r\n\r\n"), |
| 16260 | }; |
| 16261 | MockRead data_reads[] = { |
| 16262 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16263 | MockRead(SYNCHRONOUS, OK), |
| 16264 | }; |
| 16265 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16266 | arraysize(data_writes)); |
| 16267 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16268 | |
| 16269 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16270 | data_writes, arraysize(data_writes)); |
| 16271 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16272 | |
| 16273 | // Start a request that will be throttled at start; confirm it |
| 16274 | // doesn't complete. |
| 16275 | throttler->set_throttle_new_requests(true); |
| 16276 | std::unique_ptr<HttpTransaction> trans( |
| 16277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16278 | |
| 16279 | TestCompletionCallback callback; |
| 16280 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16281 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16282 | |
| 16283 | base::RunLoop().RunUntilIdle(); |
| 16284 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16285 | EXPECT_FALSE(callback.have_result()); |
| 16286 | |
| 16287 | // Create a new request, call SetPriority on it to unthrottle, |
| 16288 | // and make sure that allows the original request to complete. |
| 16289 | std::unique_ptr<HttpTransaction> trans1( |
| 16290 | new HttpNetworkTransaction(LOW, session.get())); |
| 16291 | throttler->set_priority_change_closure( |
| 16292 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16293 | base::Unretained(throttler))); |
| 16294 | |
| 16295 | // Start the transaction to associate a throttle with it. |
| 16296 | TestCompletionCallback callback1; |
| 16297 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16299 | |
| 16300 | trans1->SetPriority(IDLE); |
| 16301 | |
| 16302 | base::RunLoop().RunUntilIdle(); |
| 16303 | ASSERT_TRUE(callback.have_result()); |
| 16304 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16305 | ASSERT_TRUE(callback1.have_result()); |
| 16306 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16307 | } |
| 16308 | |
| 16309 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
| 16310 | void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {} |
| 16311 | |
| 16312 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16313 | // throttler works properly. |
| 16314 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16315 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16316 | std::unique_ptr<HttpNetworkSession> session( |
| 16317 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16318 | |
| 16319 | // Send a simple request and make sure it goes through. |
| 16320 | HttpRequestInfo request; |
| 16321 | request.method = "GET"; |
| 16322 | request.url = GURL("http://www.example.org/"); |
| 16323 | |
| 16324 | MockWrite data_writes[] = { |
| 16325 | MockWrite("GET / HTTP/1.1\r\n" |
| 16326 | "Host: www.example.org\r\n" |
| 16327 | "Connection: keep-alive\r\n\r\n"), |
| 16328 | }; |
| 16329 | MockRead data_reads[] = { |
| 16330 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16331 | MockRead(SYNCHRONOUS, OK), |
| 16332 | }; |
| 16333 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16334 | arraysize(data_writes)); |
| 16335 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16336 | |
| 16337 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16338 | data_writes, arraysize(data_writes)); |
| 16339 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16340 | |
| 16341 | // Start a request that will be throttled at start; confirm it |
| 16342 | // doesn't complete. |
| 16343 | throttler->set_throttle_new_requests(true); |
| 16344 | std::unique_ptr<HttpTransaction> trans( |
| 16345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16346 | |
| 16347 | TestCompletionCallback callback; |
| 16348 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16350 | |
| 16351 | base::RunLoop().RunUntilIdle(); |
| 16352 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16353 | EXPECT_FALSE(callback.have_result()); |
| 16354 | |
| 16355 | // Arrange for the set priority call on the above transaction to delete |
| 16356 | // the transaction. |
| 16357 | HttpTransaction* trans_ptr(trans.get()); |
| 16358 | throttler->set_priority_change_closure( |
| 16359 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16360 | |
| 16361 | // Call it and check results (partially a "doesn't crash" test). |
| 16362 | trans_ptr->SetPriority(IDLE); |
| 16363 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16364 | |
| 16365 | base::RunLoop().RunUntilIdle(); |
| 16366 | ASSERT_FALSE(callback.have_result()); |
| 16367 | } |
| 16368 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16369 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16370 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16371 | const std::string https_url = "https://www.example.com"; |
| 16372 | HttpRequestInfo request; |
| 16373 | request.url = GURL(https_url); |
| 16374 | request.method = "GET"; |
| 16375 | |
| 16376 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16377 | ssl.token_binding_negotiated = true; |
| 16378 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16379 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16381 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16382 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16383 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16384 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16385 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16386 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16388 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 16389 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16391 | |
| 16392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16393 | TestCompletionCallback callback; |
| 16394 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16395 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16396 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16397 | |
| 16398 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16399 | HttpRequestHeaders headers; |
| 16400 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16401 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16402 | } |
| 16403 | #endif // !defined(OS_IOS) |
| 16404 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16405 | } // namespace net |