[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" |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 26 | #include "base/message_loop/message_loop.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 27 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 28 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 29 | #include "base/strings/utf_string_conversions.h" |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 30 | #include "base/test/scoped_task_scheduler.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 31 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 32 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 33 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 35 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 36 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 37 | #include "net/base/load_timing_info.h" |
| 38 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 39 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 40 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 42 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 43 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 44 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 45 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 46 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 47 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 48 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 49 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 50 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 54 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 56 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 57 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 58 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 59 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 60 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 61 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 62 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 63 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 64 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 65 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 66 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 67 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 68 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 69 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 70 | #include "net/log/test_net_log_entry.h" |
| 71 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 72 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 73 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 74 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 75 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 76 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 77 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/socket_test_util.h" |
| 85 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 86 | #include "net/spdy/spdy_framer.h" |
| 87 | #include "net/spdy/spdy_session.h" |
| 88 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 89 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service_defaults.h" |
| 94 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 95 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 96 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 97 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 98 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 99 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 100 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 101 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 102 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 103 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 105 | using net::test::IsError; |
| 106 | using net::test::IsOk; |
| 107 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 108 | using base::ASCIIToUTF16; |
| 109 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 110 | //----------------------------------------------------------------------------- |
| 111 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 112 | namespace net { |
| 113 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 114 | namespace { |
| 115 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 116 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 117 | public: |
| 118 | TestNetworkStreamThrottler() |
| 119 | : throttle_new_requests_(false), |
| 120 | num_set_priority_calls_(0), |
| 121 | last_priority_set_(IDLE) {} |
| 122 | |
| 123 | ~TestNetworkStreamThrottler() override { |
| 124 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 125 | } |
| 126 | |
| 127 | // NetworkThrottleManager |
| 128 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 129 | RequestPriority priority, |
| 130 | bool ignore_limits) override { |
| 131 | std::unique_ptr<TestThrottle> test_throttle( |
| 132 | new TestThrottle(throttle_new_requests_, delegate, this)); |
| 133 | outstanding_throttles_.insert(test_throttle.get()); |
| 134 | return std::move(test_throttle); |
| 135 | } |
| 136 | |
| 137 | void UnthrottleAllRequests() { |
| 138 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 139 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 140 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 141 | throttle->Unthrottle(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 146 | throttle_new_requests_ = throttle_new_requests; |
| 147 | } |
| 148 | |
| 149 | // Includes both throttled and unthrottled throttles. |
| 150 | size_t num_outstanding_requests() const { |
| 151 | return outstanding_throttles_.size(); |
| 152 | } |
| 153 | |
| 154 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 155 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 156 | void set_priority_change_closure( |
| 157 | const base::Closure& priority_change_closure) { |
| 158 | priority_change_closure_ = priority_change_closure; |
| 159 | } |
| 160 | |
| 161 | private: |
| 162 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 163 | public: |
| 164 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 165 | |
| 166 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 167 | bool IsBlocked() const override { return throttled_; } |
| 168 | RequestPriority Priority() const override { |
| 169 | NOTREACHED(); |
| 170 | return IDLE; |
| 171 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 172 | void SetPriority(RequestPriority priority) override { |
| 173 | throttler_->SetPriorityCalled(priority); |
| 174 | } |
| 175 | |
| 176 | TestThrottle(bool throttled, |
| 177 | ThrottleDelegate* delegate, |
| 178 | TestNetworkStreamThrottler* throttler) |
| 179 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 180 | |
| 181 | void Unthrottle() { |
| 182 | EXPECT_TRUE(throttled_); |
| 183 | |
| 184 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 185 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | bool throttled_; |
| 189 | ThrottleDelegate* delegate_; |
| 190 | TestNetworkStreamThrottler* throttler_; |
| 191 | }; |
| 192 | |
| 193 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 194 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 195 | outstanding_throttles_.erase(throttle); |
| 196 | } |
| 197 | |
| 198 | void SetPriorityCalled(RequestPriority priority) { |
| 199 | ++num_set_priority_calls_; |
| 200 | last_priority_set_ = priority; |
| 201 | if (!priority_change_closure_.is_null()) |
| 202 | priority_change_closure_.Run(); |
| 203 | } |
| 204 | |
| 205 | // Includes both throttled and unthrottled throttles. |
| 206 | std::set<TestThrottle*> outstanding_throttles_; |
| 207 | bool throttle_new_requests_; |
| 208 | int num_set_priority_calls_; |
| 209 | RequestPriority last_priority_set_; |
| 210 | base::Closure priority_change_closure_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 213 | }; |
| 214 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 215 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 216 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 217 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 218 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 219 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 220 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 221 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 222 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 223 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 224 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 225 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 226 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 227 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 228 | const char kAlternativeServiceHttpHeader[] = |
| 229 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 230 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 231 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 232 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 233 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 234 | } |
| 235 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 236 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 237 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 238 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 239 | } |
| 240 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 241 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 242 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 243 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 246 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 247 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 248 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 249 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 250 | if (!params) |
| 251 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 252 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 253 | if (!params->GetList("headers", &header_list)) |
| 254 | return false; |
| 255 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 256 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 257 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 262 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 263 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 265 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 267 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 268 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 269 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 270 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 271 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 272 | |
| 273 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 275 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 276 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 277 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 278 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 281 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 282 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 283 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 284 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 285 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 286 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 287 | |
| 288 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 289 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 290 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 291 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 292 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 294 | load_timing_info.send_start); |
| 295 | |
| 296 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 297 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 298 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 299 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 300 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 301 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 305 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 306 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 308 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 309 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 310 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 311 | |
| 312 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 313 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 314 | load_timing_info.proxy_resolve_end); |
| 315 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 316 | load_timing_info.send_start); |
| 317 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 318 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 319 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 320 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 321 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 322 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 326 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 327 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 328 | int connect_timing_flags) { |
| 329 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 330 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 331 | |
| 332 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 333 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 334 | load_timing_info.proxy_resolve_end); |
| 335 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 336 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 337 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 338 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 339 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 340 | load_timing_info.send_start); |
| 341 | |
| 342 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 343 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 344 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 345 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 346 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 347 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 348 | } |
| 349 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 350 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 351 | headers->SetHeader("Connection", "Upgrade"); |
| 352 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 353 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 354 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 355 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 356 | } |
| 357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 358 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 359 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 360 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 361 | } |
| 362 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 363 | // Note that the pointer written into |*throttler| will only be valid |
| 364 | // for the lifetime of the returned HttpNetworkSession. |
| 365 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 366 | SpdySessionDependencies* session_deps, |
| 367 | TestNetworkStreamThrottler** throttler) { |
| 368 | std::unique_ptr<HttpNetworkSession> session( |
| 369 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 370 | |
| 371 | std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( |
| 372 | new TestNetworkStreamThrottler); |
| 373 | *throttler = owned_throttler.get(); |
| 374 | |
| 375 | HttpNetworkSessionPeer peer(session.get()); |
| 376 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 377 | |
| 378 | return session; |
| 379 | } |
| 380 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 381 | } // namespace |
| 382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 383 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 384 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 385 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 386 | // Important to restore the per-pool limit first, since the pool limit must |
| 387 | // always be greater than group limit, and the tests reduce both limits. |
| 388 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 389 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 390 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 391 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 392 | } |
| 393 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 394 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 395 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 396 | : ssl_(ASYNC, OK), |
| 397 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 399 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 400 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 401 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 402 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 403 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 404 | struct SimpleGetHelperResult { |
| 405 | int rv; |
| 406 | std::string status_line; |
| 407 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 408 | int64_t total_received_bytes; |
| 409 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 410 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 411 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 412 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 413 | }; |
| 414 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 415 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 416 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 417 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 418 | } |
| 419 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 420 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 421 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 422 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 423 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 424 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 425 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 426 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 427 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 430 | // Either |write_failure| specifies a write failure or |read_failure| |
| 431 | // specifies a read failure when using a reused socket. In either case, the |
| 432 | // failure should cause the network transaction to resend the request, and the |
| 433 | // other argument should be NULL. |
| 434 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 435 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 436 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 437 | // Either |write_failure| specifies a write failure or |read_failure| |
| 438 | // specifies a read failure when using a reused socket. In either case, the |
| 439 | // failure should cause the network transaction to resend the request, and the |
| 440 | // other argument should be NULL. |
| 441 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 442 | const MockRead* read_failure, |
| 443 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 444 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 445 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 446 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 448 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 449 | HttpRequestInfo request; |
| 450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 451 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 452 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 453 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 454 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 457 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 458 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 459 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 460 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 462 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 464 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 465 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 467 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 468 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 469 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 470 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 471 | |
| 472 | // Even in the failure cases that use this function, connections are always |
| 473 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 474 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 475 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 476 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 477 | if (out.rv != OK) |
| 478 | return out; |
| 479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 480 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 481 | // Can't use ASSERT_* inside helper functions like this, so |
| 482 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 483 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 484 | out.rv = ERR_UNEXPECTED; |
| 485 | return out; |
| 486 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 487 | out.status_line = response->headers->GetStatusLine(); |
| 488 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 489 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 490 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 491 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 492 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 493 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 494 | EXPECT_EQ(got_endpoint, |
| 495 | out.remote_endpoint_after_start.address().size() > 0); |
| 496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 497 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 498 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 499 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 500 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 501 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 502 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 503 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 504 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 505 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 506 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 507 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 508 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 509 | std::string line; |
| 510 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 511 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 512 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 513 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 514 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 515 | std::string value; |
| 516 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 517 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 518 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 519 | EXPECT_EQ("keep-alive", value); |
| 520 | |
| 521 | std::string response_headers; |
| 522 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 523 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 524 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 526 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 527 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 528 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 530 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 531 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 532 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 533 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 534 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 535 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | MockWrite data_writes[] = { |
| 537 | MockWrite("GET / HTTP/1.1\r\n" |
| 538 | "Host: www.example.org\r\n" |
| 539 | "Connection: keep-alive\r\n\r\n"), |
| 540 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 541 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 542 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 543 | arraysize(data_writes)); |
| 544 | StaticSocketDataProvider* data[] = {&reads}; |
| 545 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 546 | |
| 547 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 548 | out.total_sent_bytes); |
| 549 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 550 | } |
| 551 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 552 | void AddSSLSocketData() { |
| 553 | ssl_.next_proto = kProtoHTTP2; |
| 554 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 555 | ASSERT_TRUE(ssl_.cert); |
| 556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 557 | } |
| 558 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 559 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 560 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 561 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 562 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 563 | |
| 564 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 565 | |
| 566 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 567 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 568 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 569 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 570 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 571 | |
| 572 | // Original socket limits. Some tests set these. Safest to always restore |
| 573 | // them once each test has been run. |
| 574 | int old_max_group_sockets_; |
| 575 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 576 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 577 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 578 | namespace { |
| 579 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 580 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 581 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 582 | BeforeHeadersSentHandler() |
| 583 | : observed_before_headers_sent_with_proxy_(false), |
| 584 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 585 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 586 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 587 | HttpRequestHeaders* request_headers) { |
| 588 | observed_before_headers_sent_ = true; |
| 589 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 590 | !proxy_info.is_quic()) { |
| 591 | return; |
| 592 | } |
| 593 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 594 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 595 | } |
| 596 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | bool observed_before_headers_sent_with_proxy() const { |
| 598 | return observed_before_headers_sent_with_proxy_; |
| 599 | } |
| 600 | |
| 601 | bool observed_before_headers_sent() const { |
| 602 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | std::string observed_proxy_server_uri() const { |
| 606 | return observed_proxy_server_uri_; |
| 607 | } |
| 608 | |
| 609 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 610 | bool observed_before_headers_sent_with_proxy_; |
| 611 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 612 | std::string observed_proxy_server_uri_; |
| 613 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 614 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 615 | }; |
| 616 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 617 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 618 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 619 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 620 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 621 | const int sizeof_row = strlen(row); |
| 622 | const int num_rows = static_cast<int>( |
| 623 | ceil(static_cast<float>(size) / sizeof_row)); |
| 624 | const int sizeof_data = num_rows * sizeof_row; |
| 625 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 626 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 627 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 628 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 629 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 630 | } |
| 631 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 632 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 633 | // Alternative functions that eliminate randomness and dependency on the local |
| 634 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 635 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 636 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 637 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 638 | static size_t current_byte = 0; |
| 639 | for (size_t i = 0; i < n; ++i) { |
| 640 | output[i] = bytes[current_byte++]; |
| 641 | current_byte %= arraysize(bytes); |
| 642 | } |
| 643 | } |
| 644 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 645 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 646 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 647 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 648 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 649 | static size_t current_byte = 0; |
| 650 | for (size_t i = 0; i < n; ++i) { |
| 651 | output[i] = bytes[current_byte++]; |
| 652 | current_byte %= arraysize(bytes); |
| 653 | } |
| 654 | } |
| 655 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 656 | std::string MockGetHostName() { |
| 657 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 658 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 659 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 660 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 661 | template<typename ParentPool> |
| 662 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 663 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 664 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 665 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 666 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 667 | const std::string last_group_name_received() const { |
| 668 | return last_group_name_; |
| 669 | } |
| 670 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 671 | int RequestSocket(const std::string& group_name, |
| 672 | const void* socket_params, |
| 673 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 674 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 675 | ClientSocketHandle* handle, |
| 676 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 677 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 678 | last_group_name_ = group_name; |
| 679 | return ERR_IO_PENDING; |
| 680 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 681 | void CancelRequest(const std::string& group_name, |
| 682 | ClientSocketHandle* handle) override {} |
| 683 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 684 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 685 | int id) override {} |
| 686 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 687 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 688 | int IdleSocketCount() const override { return 0; } |
| 689 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 690 | return 0; |
| 691 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 692 | LoadState GetLoadState(const std::string& group_name, |
| 693 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 694 | return LOAD_STATE_IDLE; |
| 695 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 697 | return base::TimeDelta(); |
| 698 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 699 | |
| 700 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 701 | std::string last_group_name_; |
| 702 | }; |
| 703 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 704 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 705 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 706 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 707 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 708 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 709 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 710 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 711 | CaptureGroupNameSSLSocketPool; |
| 712 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 713 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 714 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 715 | HostResolver* host_resolver, |
| 716 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 717 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 718 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 719 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 720 | CaptureGroupNameHttpProxySocketPool::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 */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 723 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 724 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 725 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 726 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 727 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 728 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 729 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 730 | : SSLClientSocketPool(0, |
| 731 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 732 | cert_verifier, |
| 733 | NULL, |
| 734 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 735 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 736 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 737 | std::string(), |
| 738 | NULL, |
| 739 | NULL, |
| 740 | NULL, |
| 741 | NULL, |
| 742 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 743 | NULL) { |
| 744 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 745 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | //----------------------------------------------------------------------------- |
| 747 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 748 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 749 | // configured for common cases. |
| 750 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 751 | if (!auth_challenge) |
| 752 | return false; |
| 753 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 754 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 756 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | return true; |
| 758 | } |
| 759 | |
| 760 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 761 | if (!auth_challenge) |
| 762 | return false; |
| 763 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 764 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 765 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 766 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 771 | if (!auth_challenge) |
| 772 | return false; |
| 773 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 774 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 775 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 776 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 777 | return true; |
| 778 | } |
| 779 | |
| 780 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 781 | if (!auth_challenge) |
| 782 | return false; |
| 783 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 784 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 785 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 786 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 787 | return true; |
| 788 | } |
| 789 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 790 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 791 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 792 | if (!auth_challenge) |
| 793 | return false; |
| 794 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 795 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 796 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 797 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 798 | return true; |
| 799 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 800 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 801 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 802 | } // namespace |
| 803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 804 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 806 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | } |
| 808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 809 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 810 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 811 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 812 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 813 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 815 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 816 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 817 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 819 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 820 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 821 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 822 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 823 | |
| 824 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 828 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 829 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 830 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 835 | EXPECT_THAT(out.rv, IsOk()); |
| 836 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 837 | EXPECT_EQ("hello world", out.response_data); |
| 838 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 839 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 840 | } |
| 841 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | // Response with no status line, and a weird port. Should fail by default. |
| 843 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 844 | MockRead data_reads[] = { |
| 845 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 846 | }; |
| 847 | |
| 848 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 850 | |
| 851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 852 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 853 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 854 | std::unique_ptr<HttpTransaction> trans( |
| 855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 856 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 857 | request.method = "GET"; |
| 858 | request.url = GURL("http://www.example.com:2000/"); |
| 859 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 860 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 861 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 862 | } |
| 863 | |
| 864 | // Response with no status line, and a weird port. Option to allow weird ports |
| 865 | // enabled. |
| 866 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 867 | MockRead data_reads[] = { |
| 868 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 869 | }; |
| 870 | |
| 871 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 873 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 875 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 876 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 877 | std::unique_ptr<HttpTransaction> trans( |
| 878 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 879 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 880 | request.method = "GET"; |
| 881 | request.url = GURL("http://www.example.com:2000/"); |
| 882 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 883 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 884 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 885 | |
| 886 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 887 | ASSERT_TRUE(info->headers); |
| 888 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 889 | |
| 890 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 891 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 892 | } |
| 893 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 894 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 895 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 896 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 897 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 898 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 899 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 900 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 901 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 902 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 903 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 904 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 905 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 906 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 910 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 912 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 913 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 915 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 916 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 917 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 918 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 919 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 920 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 921 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 925 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 927 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 928 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 929 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 930 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 931 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 932 | EXPECT_THAT(out.rv, IsOk()); |
| 933 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 934 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 935 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 936 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 940 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 942 | MockRead("\n"), |
| 943 | MockRead("\n"), |
| 944 | MockRead("Q"), |
| 945 | MockRead("J"), |
| 946 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 948 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 949 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 950 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 951 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 952 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 953 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 954 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 955 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 959 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 961 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 962 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 963 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 964 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 965 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 966 | EXPECT_THAT(out.rv, IsOk()); |
| 967 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 968 | EXPECT_EQ("HTT", out.response_data); |
| 969 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 970 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 971 | } |
| 972 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 973 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 974 | // persistent connection. The response should still terminate since a 204 |
| 975 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 976 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 977 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 978 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 979 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 980 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 982 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 983 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 984 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 985 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 986 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 987 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 988 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 989 | int64_t response_size = reads_size - strlen(junk); |
| 990 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | } |
| 992 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 993 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 995 | std::string final_chunk = "0\r\n\r\n"; |
| 996 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 997 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1000 | MockRead("5\r\nHello\r\n"), |
| 1001 | MockRead("1\r\n"), |
| 1002 | MockRead(" \r\n"), |
| 1003 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1004 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1005 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1006 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1007 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1008 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1009 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1011 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1012 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1013 | int64_t response_size = reads_size - extra_data.size(); |
| 1014 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1015 | } |
| 1016 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1017 | // Next tests deal with http://crbug.com/56344. |
| 1018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1019 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1020 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1021 | MockRead data_reads[] = { |
| 1022 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1023 | MockRead("Content-Length: 10\r\n"), |
| 1024 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1025 | }; |
| 1026 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1027 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1028 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1029 | } |
| 1030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1031 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1032 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1033 | MockRead data_reads[] = { |
| 1034 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1035 | MockRead("Content-Length: 5\r\n"), |
| 1036 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1037 | MockRead("Hello"), |
| 1038 | }; |
| 1039 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1040 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1041 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1042 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1043 | EXPECT_EQ("Hello", out.response_data); |
| 1044 | } |
| 1045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1046 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1047 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1048 | // More than 2 dupes. |
| 1049 | { |
| 1050 | MockRead data_reads[] = { |
| 1051 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1052 | MockRead("Content-Length: 5\r\n"), |
| 1053 | MockRead("Content-Length: 5\r\n"), |
| 1054 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1055 | MockRead("Hello"), |
| 1056 | }; |
| 1057 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1058 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1059 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1060 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1061 | EXPECT_EQ("Hello", out.response_data); |
| 1062 | } |
| 1063 | // HTTP/1.0 |
| 1064 | { |
| 1065 | MockRead data_reads[] = { |
| 1066 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n"), |
| 1069 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1070 | MockRead("Hello"), |
| 1071 | }; |
| 1072 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1073 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1074 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1075 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1076 | EXPECT_EQ("Hello", out.response_data); |
| 1077 | } |
| 1078 | // 2 dupes and one mismatched. |
| 1079 | { |
| 1080 | MockRead data_reads[] = { |
| 1081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1082 | MockRead("Content-Length: 10\r\n"), |
| 1083 | MockRead("Content-Length: 10\r\n"), |
| 1084 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1085 | }; |
| 1086 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1087 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1088 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1092 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1093 | MultipleContentLengthHeadersTransferEncoding) { |
| 1094 | MockRead data_reads[] = { |
| 1095 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1096 | MockRead("Content-Length: 666\r\n"), |
| 1097 | MockRead("Content-Length: 1337\r\n"), |
| 1098 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1099 | MockRead("5\r\nHello\r\n"), |
| 1100 | MockRead("1\r\n"), |
| 1101 | MockRead(" \r\n"), |
| 1102 | MockRead("5\r\nworld\r\n"), |
| 1103 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1105 | }; |
| 1106 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1107 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1108 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1109 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1110 | EXPECT_EQ("Hello world", out.response_data); |
| 1111 | } |
| 1112 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1113 | // Next tests deal with http://crbug.com/98895. |
| 1114 | |
| 1115 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1116 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1117 | MockRead data_reads[] = { |
| 1118 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1119 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1120 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1121 | MockRead("Hello"), |
| 1122 | }; |
| 1123 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1124 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1125 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1127 | EXPECT_EQ("Hello", out.response_data); |
| 1128 | } |
| 1129 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1130 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1131 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | MockRead data_reads[] = { |
| 1133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1134 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1135 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1136 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1137 | MockRead("Hello"), |
| 1138 | }; |
| 1139 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1140 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1141 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1142 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1143 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1147 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1148 | MockRead data_reads[] = { |
| 1149 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1150 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1151 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1152 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1153 | MockRead("Hello"), |
| 1154 | }; |
| 1155 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1156 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1157 | EXPECT_THAT(out.rv, |
| 1158 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1159 | } |
| 1160 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1161 | // Checks that two identical Location headers result in no error. |
| 1162 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1163 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1164 | MockRead data_reads[] = { |
| 1165 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1166 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1167 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1169 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | }; |
| 1171 | |
| 1172 | HttpRequestInfo request; |
| 1173 | request.method = "GET"; |
| 1174 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1178 | |
| 1179 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1182 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1184 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1187 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1189 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1190 | ASSERT_TRUE(response); |
| 1191 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1193 | std::string url; |
| 1194 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1195 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1196 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1200 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | MockRead data_reads[] = { |
| 1202 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1203 | MockRead("Location: http://good.com/\r\n"), |
| 1204 | MockRead("Location: http://evil.com/\r\n"), |
| 1205 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1206 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1207 | }; |
| 1208 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1209 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1210 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | } |
| 1212 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1213 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1214 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1215 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1216 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1218 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1219 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1222 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1223 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1224 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1225 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1226 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1227 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1228 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1229 | "Host: www.example.org\r\n" |
| 1230 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1231 | }; |
| 1232 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1233 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1234 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1235 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1236 | // No response body because the test stops reading here. |
| 1237 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1238 | }; |
| 1239 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1240 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1241 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1244 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1246 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | |
| 1249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1253 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
| 1255 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1256 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1258 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1259 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1260 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1261 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | |
| 1263 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1264 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1265 | bool has_server_header = response->headers->EnumerateHeader( |
| 1266 | &iter, "Server", &server_header); |
| 1267 | EXPECT_TRUE(has_server_header); |
| 1268 | EXPECT_EQ("Blah", server_header); |
| 1269 | |
| 1270 | // Reading should give EOF right away, since there is no message body |
| 1271 | // (despite non-zero content-length). |
| 1272 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1273 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1275 | EXPECT_EQ("", response_data); |
| 1276 | } |
| 1277 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1278 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1280 | |
| 1281 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1282 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1283 | MockRead("hello"), |
| 1284 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1285 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1286 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1287 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1288 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1291 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | "hello", "world" |
| 1293 | }; |
| 1294 | |
| 1295 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1296 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1298 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1302 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1304 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
| 1307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1308 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1310 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1311 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1313 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1314 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1315 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
| 1317 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1318 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1319 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1320 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1324 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1325 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1326 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1327 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1328 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1329 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1330 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | request.method = "POST"; |
| 1332 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1333 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1335 | // Check the upload progress returned before initialization is correct. |
| 1336 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1337 | EXPECT_EQ(0u, progress.size()); |
| 1338 | EXPECT_EQ(0u, progress.position()); |
| 1339 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1341 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1342 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1344 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1345 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1346 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1347 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
| 1357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1358 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1360 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1361 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1363 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1364 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
| 1366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1367 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1369 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | } |
| 1371 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1372 | // This test is almost the same as Ignores100 above, but the response contains |
| 1373 | // 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] | 1374 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1375 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1376 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1377 | request.method = "GET"; |
| 1378 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1381 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1382 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1383 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1384 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1385 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1387 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1388 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1392 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1394 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1396 | |
| 1397 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1398 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1400 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1401 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1403 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1404 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1405 | |
| 1406 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1407 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1408 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1409 | EXPECT_EQ("hello world", response_data); |
| 1410 | } |
| 1411 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1412 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1413 | HttpRequestInfo request; |
| 1414 | request.method = "POST"; |
| 1415 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1418 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1419 | |
| 1420 | MockRead data_reads[] = { |
| 1421 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1422 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1423 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1426 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1427 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1429 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1431 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1432 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1434 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1435 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1436 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1437 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1438 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1439 | } |
| 1440 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1441 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1442 | HttpRequestInfo request; |
| 1443 | request.method = "POST"; |
| 1444 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1448 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1449 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1450 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1451 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1452 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1455 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1456 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1457 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1459 | |
| 1460 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1461 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1462 | } |
| 1463 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1464 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1465 | const MockWrite* write_failure, |
| 1466 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1467 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1468 | request.method = "GET"; |
| 1469 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1470 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1471 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1472 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1474 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1475 | // Written data for successfully sending both requests. |
| 1476 | MockWrite data1_writes[] = { |
| 1477 | MockWrite("GET / HTTP/1.1\r\n" |
| 1478 | "Host: www.foo.com\r\n" |
| 1479 | "Connection: keep-alive\r\n\r\n"), |
| 1480 | MockWrite("GET / HTTP/1.1\r\n" |
| 1481 | "Host: www.foo.com\r\n" |
| 1482 | "Connection: keep-alive\r\n\r\n") |
| 1483 | }; |
| 1484 | |
| 1485 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1486 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1487 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1488 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1489 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1490 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1491 | |
| 1492 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1493 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1494 | data1_writes[1] = *write_failure; |
| 1495 | } else { |
| 1496 | ASSERT_TRUE(read_failure); |
| 1497 | data1_reads[2] = *read_failure; |
| 1498 | } |
| 1499 | |
| 1500 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1501 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1502 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1503 | |
| 1504 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1505 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1506 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1507 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1508 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1509 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1510 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1511 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1512 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1513 | "hello", "world" |
| 1514 | }; |
| 1515 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1516 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1517 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1518 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1520 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1522 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1524 | |
| 1525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1526 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1527 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1528 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1529 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1530 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1531 | if (i == 0) { |
| 1532 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1533 | } else { |
| 1534 | // The second request should be using a new socket. |
| 1535 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1536 | } |
| 1537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1539 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1540 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1541 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1542 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1543 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1544 | |
| 1545 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1546 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1548 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1549 | } |
| 1550 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1551 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1552 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1553 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1554 | const MockRead* read_failure, |
| 1555 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | HttpRequestInfo request; |
| 1557 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1558 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1559 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1560 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1561 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1563 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1564 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1565 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1566 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1567 | ssl1.next_proto = kProtoHTTP2; |
| 1568 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1569 | } |
| 1570 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1572 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1573 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1574 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1575 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1576 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1577 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1578 | SpdySerializedFrame spdy_data( |
| 1579 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1580 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1581 | // HTTP/1.1 versions of the request and response. |
| 1582 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1583 | "Host: www.foo.com\r\n" |
| 1584 | "Connection: keep-alive\r\n\r\n"; |
| 1585 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1586 | const char kHttpData[] = "hello"; |
| 1587 | |
| 1588 | std::vector<MockRead> data1_reads; |
| 1589 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1590 | if (write_failure) { |
| 1591 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1592 | data1_writes.push_back(*write_failure); |
| 1593 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1594 | } else { |
| 1595 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1596 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1597 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1598 | } else { |
| 1599 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1600 | } |
| 1601 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1602 | } |
| 1603 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1604 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1605 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1606 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1607 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1608 | std::vector<MockRead> data2_reads; |
| 1609 | std::vector<MockWrite> data2_writes; |
| 1610 | |
| 1611 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1612 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1613 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1614 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1615 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1616 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1617 | } else { |
| 1618 | data2_writes.push_back( |
| 1619 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1620 | |
| 1621 | data2_reads.push_back( |
| 1622 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1623 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1624 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1625 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1626 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1627 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1628 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1629 | |
| 1630 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1631 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1632 | // Wait for the preconnect to complete. |
| 1633 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1634 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1635 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1636 | |
| 1637 | // Make the request. |
| 1638 | TestCompletionCallback callback; |
| 1639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1642 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1644 | |
| 1645 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1647 | |
| 1648 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1649 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1650 | TestLoadTimingNotReused( |
| 1651 | load_timing_info, |
| 1652 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1655 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1656 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1657 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1658 | if (response->was_fetched_via_spdy) { |
| 1659 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1660 | } else { |
| 1661 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1662 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1663 | |
| 1664 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1665 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1666 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1667 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1668 | } |
| 1669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1670 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1671 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1672 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1673 | } |
| 1674 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1675 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1676 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1677 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1678 | } |
| 1679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1680 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1681 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1682 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1683 | } |
| 1684 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1685 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1686 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1687 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1688 | MockRead read_failure(SYNCHRONOUS, |
| 1689 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1690 | "Connection: Keep-Alive\r\n" |
| 1691 | "Content-Length: 6\r\n\r\n" |
| 1692 | "Pickle"); |
| 1693 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1694 | } |
| 1695 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1696 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1697 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1698 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1699 | } |
| 1700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1701 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1702 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1703 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1704 | } |
| 1705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1706 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1707 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1708 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1709 | } |
| 1710 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1711 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1712 | MockRead read_failure(ASYNC, OK); // EOF |
| 1713 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1714 | } |
| 1715 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1716 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1717 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1718 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1719 | MockRead read_failure(SYNCHRONOUS, |
| 1720 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1721 | "Connection: Keep-Alive\r\n" |
| 1722 | "Content-Length: 6\r\n\r\n" |
| 1723 | "Pickle"); |
| 1724 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1725 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1726 | } |
| 1727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1728 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1729 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1730 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1731 | } |
| 1732 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1733 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1734 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1735 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1736 | } |
| 1737 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1738 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1739 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1740 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1741 | } |
| 1742 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1743 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1744 | MockRead read_failure(ASYNC, OK); // EOF |
| 1745 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1746 | } |
| 1747 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1748 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1749 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1751 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1755 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1756 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1757 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1758 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1759 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1760 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1761 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1762 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1765 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1766 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1767 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1769 | |
| 1770 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1771 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1772 | |
| 1773 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1774 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1775 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | // What do various browsers do when the server closes a non-keepalive |
| 1779 | // connection without sending any response header or body? |
| 1780 | // |
| 1781 | // IE7: error page |
| 1782 | // Safari 3.1.2 (Windows): error page |
| 1783 | // Firefox 3.0.1: blank page |
| 1784 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1785 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1786 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1787 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1788 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1789 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1790 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1791 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1792 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1793 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1794 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1795 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1796 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1797 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1798 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1799 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1800 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1801 | // destructor in such situations. |
| 1802 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1803 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | HttpRequestInfo request; |
| 1805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1806 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1809 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1810 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1811 | |
| 1812 | MockRead data_reads[] = { |
| 1813 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1814 | MockRead("Connection: keep-alive\r\n"), |
| 1815 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1816 | MockRead("hello"), |
| 1817 | MockRead(SYNCHRONOUS, 0), |
| 1818 | }; |
| 1819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1821 | |
| 1822 | TestCompletionCallback callback; |
| 1823 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1824 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1826 | |
| 1827 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1829 | |
| 1830 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1831 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1832 | if (rv == ERR_IO_PENDING) |
| 1833 | rv = callback.WaitForResult(); |
| 1834 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1835 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1836 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1837 | |
| 1838 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1839 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1840 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1841 | } |
| 1842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1843 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1844 | HttpRequestInfo request; |
| 1845 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1846 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1849 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1850 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1851 | |
| 1852 | MockRead data_reads[] = { |
| 1853 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1854 | MockRead("Connection: keep-alive\r\n"), |
| 1855 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1856 | MockRead(SYNCHRONOUS, 0), |
| 1857 | }; |
| 1858 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1860 | |
| 1861 | TestCompletionCallback callback; |
| 1862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1863 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1865 | |
| 1866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1867 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1868 | |
| 1869 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1870 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1871 | if (rv == ERR_IO_PENDING) |
| 1872 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1873 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1874 | |
| 1875 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1876 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1877 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1878 | } |
| 1879 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1880 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1881 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1882 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1883 | HttpRequestInfo request; |
| 1884 | request.method = "GET"; |
| 1885 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1886 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1887 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1888 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1890 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1891 | const char* request_data = |
| 1892 | "GET / HTTP/1.1\r\n" |
| 1893 | "Host: www.foo.com\r\n" |
| 1894 | "Connection: keep-alive\r\n\r\n"; |
| 1895 | MockWrite data_writes[] = { |
| 1896 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1897 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1898 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1899 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1900 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1901 | }; |
| 1902 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1903 | // Note that because all these reads happen in the same |
| 1904 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1905 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1906 | MockRead data_reads[] = { |
| 1907 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1908 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1909 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1910 | MockRead(ASYNC, 7, |
| 1911 | "HTTP/1.1 302 Found\r\n" |
| 1912 | "Content-Length: 0\r\n\r\n"), |
| 1913 | MockRead(ASYNC, 9, |
| 1914 | "HTTP/1.1 302 Found\r\n" |
| 1915 | "Content-Length: 5\r\n\r\n" |
| 1916 | "hello"), |
| 1917 | MockRead(ASYNC, 11, |
| 1918 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1919 | "Content-Length: 0\r\n\r\n"), |
| 1920 | MockRead(ASYNC, 13, |
| 1921 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1922 | "Content-Length: 5\r\n\r\n" |
| 1923 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1924 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1925 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1926 | // the set_busy_before_sync_reads(true) call, while the |
| 1927 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1928 | // reuseable. See http://crbug.com/544255. |
| 1929 | MockRead(ASYNC, 15, |
| 1930 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1931 | "Content-Length: 5\r\n\r\n"), |
| 1932 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1933 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1934 | MockRead(ASYNC, 18, |
| 1935 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1936 | "Content-Length: 5\r\n\r\n" |
| 1937 | "he"), |
| 1938 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1939 | |
| 1940 | // The body of the final request is actually read. |
| 1941 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1942 | MockRead(ASYNC, 22, "hello"), |
| 1943 | }; |
| 1944 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1945 | arraysize(data_writes)); |
| 1946 | data.set_busy_before_sync_reads(true); |
| 1947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1948 | |
| 1949 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1950 | std::string response_lines[kNumUnreadBodies]; |
| 1951 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1952 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1953 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1954 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1956 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1957 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1958 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1959 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1960 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1961 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1962 | LoadTimingInfo load_timing_info; |
| 1963 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1964 | if (i == 0) { |
| 1965 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1966 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1967 | } else { |
| 1968 | TestLoadTimingReused(load_timing_info); |
| 1969 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1970 | } |
| 1971 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1972 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1973 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1974 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1975 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1976 | response_lines[i] = response->headers->GetStatusLine(); |
| 1977 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1978 | // Delete the transaction without reading the response bodies. Then spin |
| 1979 | // the message loop, so the response bodies are drained. |
| 1980 | trans.reset(); |
| 1981 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1982 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1983 | |
| 1984 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1985 | "HTTP/1.1 204 No Content", |
| 1986 | "HTTP/1.1 205 Reset Content", |
| 1987 | "HTTP/1.1 304 Not Modified", |
| 1988 | "HTTP/1.1 302 Found", |
| 1989 | "HTTP/1.1 302 Found", |
| 1990 | "HTTP/1.1 301 Moved Permanently", |
| 1991 | "HTTP/1.1 301 Moved Permanently", |
| 1992 | "HTTP/1.1 200 Hunky-Dory", |
| 1993 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1994 | }; |
| 1995 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1996 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1997 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1998 | |
| 1999 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2000 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2002 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2005 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2007 | ASSERT_TRUE(response); |
| 2008 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2009 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2010 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2011 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2012 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2013 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2014 | } |
| 2015 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2016 | // Sockets that receive extra data after a response is complete should not be |
| 2017 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2018 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2020 | MockWrite data_writes1[] = { |
| 2021 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2022 | "Host: www.borked.com\r\n" |
| 2023 | "Connection: keep-alive\r\n\r\n"), |
| 2024 | }; |
| 2025 | |
| 2026 | MockRead data_reads1[] = { |
| 2027 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2028 | "Connection: keep-alive\r\n" |
| 2029 | "Content-Length: 22\r\n\r\n" |
| 2030 | "This server is borked."), |
| 2031 | }; |
| 2032 | |
| 2033 | MockWrite data_writes2[] = { |
| 2034 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2035 | "Host: www.borked.com\r\n" |
| 2036 | "Connection: keep-alive\r\n\r\n"), |
| 2037 | }; |
| 2038 | |
| 2039 | MockRead data_reads2[] = { |
| 2040 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2041 | "Content-Length: 3\r\n\r\n" |
| 2042 | "foo"), |
| 2043 | }; |
| 2044 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2045 | data_writes1, arraysize(data_writes1)); |
| 2046 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2047 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2048 | data_writes2, arraysize(data_writes2)); |
| 2049 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2050 | |
| 2051 | TestCompletionCallback callback; |
| 2052 | HttpRequestInfo request1; |
| 2053 | request1.method = "HEAD"; |
| 2054 | request1.url = GURL("http://www.borked.com/"); |
| 2055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2056 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2057 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2058 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2060 | |
| 2061 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2062 | ASSERT_TRUE(response1); |
| 2063 | ASSERT_TRUE(response1->headers); |
| 2064 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2065 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2066 | |
| 2067 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2068 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2069 | EXPECT_EQ("", response_data1); |
| 2070 | // Deleting the transaction attempts to release the socket back into the |
| 2071 | // socket pool. |
| 2072 | trans1.reset(); |
| 2073 | |
| 2074 | HttpRequestInfo request2; |
| 2075 | request2.method = "GET"; |
| 2076 | request2.url = GURL("http://www.borked.com/foo"); |
| 2077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2078 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2080 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2081 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2082 | |
| 2083 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2084 | ASSERT_TRUE(response2); |
| 2085 | ASSERT_TRUE(response2->headers); |
| 2086 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2087 | |
| 2088 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2089 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2090 | EXPECT_EQ("foo", response_data2); |
| 2091 | } |
| 2092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2093 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2095 | MockWrite data_writes1[] = { |
| 2096 | MockWrite("GET / HTTP/1.1\r\n" |
| 2097 | "Host: www.borked.com\r\n" |
| 2098 | "Connection: keep-alive\r\n\r\n"), |
| 2099 | }; |
| 2100 | |
| 2101 | MockRead data_reads1[] = { |
| 2102 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2103 | "Connection: keep-alive\r\n" |
| 2104 | "Content-Length: 22\r\n\r\n" |
| 2105 | "This server is borked." |
| 2106 | "Bonus data!"), |
| 2107 | }; |
| 2108 | |
| 2109 | MockWrite data_writes2[] = { |
| 2110 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2111 | "Host: www.borked.com\r\n" |
| 2112 | "Connection: keep-alive\r\n\r\n"), |
| 2113 | }; |
| 2114 | |
| 2115 | MockRead data_reads2[] = { |
| 2116 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2117 | "Content-Length: 3\r\n\r\n" |
| 2118 | "foo"), |
| 2119 | }; |
| 2120 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2121 | data_writes1, arraysize(data_writes1)); |
| 2122 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2123 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2124 | data_writes2, arraysize(data_writes2)); |
| 2125 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2126 | |
| 2127 | TestCompletionCallback callback; |
| 2128 | HttpRequestInfo request1; |
| 2129 | request1.method = "GET"; |
| 2130 | request1.url = GURL("http://www.borked.com/"); |
| 2131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2132 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2134 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2135 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2136 | |
| 2137 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2138 | ASSERT_TRUE(response1); |
| 2139 | ASSERT_TRUE(response1->headers); |
| 2140 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2141 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2142 | |
| 2143 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2144 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2145 | EXPECT_EQ("This server is borked.", response_data1); |
| 2146 | // Deleting the transaction attempts to release the socket back into the |
| 2147 | // socket pool. |
| 2148 | trans1.reset(); |
| 2149 | |
| 2150 | HttpRequestInfo request2; |
| 2151 | request2.method = "GET"; |
| 2152 | request2.url = GURL("http://www.borked.com/foo"); |
| 2153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2154 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2156 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2157 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2158 | |
| 2159 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2160 | ASSERT_TRUE(response2); |
| 2161 | ASSERT_TRUE(response2->headers); |
| 2162 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2163 | |
| 2164 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2165 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2166 | EXPECT_EQ("foo", response_data2); |
| 2167 | } |
| 2168 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2169 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2171 | MockWrite data_writes1[] = { |
| 2172 | MockWrite("GET / HTTP/1.1\r\n" |
| 2173 | "Host: www.borked.com\r\n" |
| 2174 | "Connection: keep-alive\r\n\r\n"), |
| 2175 | }; |
| 2176 | |
| 2177 | MockRead data_reads1[] = { |
| 2178 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2179 | "Connection: keep-alive\r\n" |
| 2180 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2181 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2182 | MockRead("0\r\n\r\nBonus data!"), |
| 2183 | }; |
| 2184 | |
| 2185 | MockWrite data_writes2[] = { |
| 2186 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2187 | "Host: www.borked.com\r\n" |
| 2188 | "Connection: keep-alive\r\n\r\n"), |
| 2189 | }; |
| 2190 | |
| 2191 | MockRead data_reads2[] = { |
| 2192 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2193 | "Content-Length: 3\r\n\r\n" |
| 2194 | "foo"), |
| 2195 | }; |
| 2196 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2197 | data_writes1, arraysize(data_writes1)); |
| 2198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2199 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2200 | data_writes2, arraysize(data_writes2)); |
| 2201 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2202 | |
| 2203 | TestCompletionCallback callback; |
| 2204 | HttpRequestInfo request1; |
| 2205 | request1.method = "GET"; |
| 2206 | request1.url = GURL("http://www.borked.com/"); |
| 2207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2208 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2210 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2211 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2212 | |
| 2213 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2214 | ASSERT_TRUE(response1); |
| 2215 | ASSERT_TRUE(response1->headers); |
| 2216 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2217 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2218 | |
| 2219 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2220 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2221 | EXPECT_EQ("This server is borked.", response_data1); |
| 2222 | // Deleting the transaction attempts to release the socket back into the |
| 2223 | // socket pool. |
| 2224 | trans1.reset(); |
| 2225 | |
| 2226 | HttpRequestInfo request2; |
| 2227 | request2.method = "GET"; |
| 2228 | request2.url = GURL("http://www.borked.com/foo"); |
| 2229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2230 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2232 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2233 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2234 | |
| 2235 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2236 | ASSERT_TRUE(response2); |
| 2237 | ASSERT_TRUE(response2->headers); |
| 2238 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2239 | |
| 2240 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2241 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2242 | EXPECT_EQ("foo", response_data2); |
| 2243 | } |
| 2244 | |
| 2245 | // This is a little different from the others - it tests the case that the |
| 2246 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2247 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2248 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2249 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2251 | MockWrite data_writes1[] = { |
| 2252 | MockWrite("GET / HTTP/1.1\r\n" |
| 2253 | "Host: www.borked.com\r\n" |
| 2254 | "Connection: keep-alive\r\n\r\n"), |
| 2255 | }; |
| 2256 | |
| 2257 | MockRead data_reads1[] = { |
| 2258 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2259 | "Connection: keep-alive\r\n" |
| 2260 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2261 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2262 | MockRead("0\r\n\r\nBonus data!"), |
| 2263 | }; |
| 2264 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2265 | data_writes1, arraysize(data_writes1)); |
| 2266 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2267 | |
| 2268 | TestCompletionCallback callback; |
| 2269 | HttpRequestInfo request1; |
| 2270 | request1.method = "GET"; |
| 2271 | request1.url = GURL("http://www.borked.com/"); |
| 2272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2273 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2274 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2275 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2276 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2277 | |
| 2278 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2279 | ASSERT_TRUE(response1); |
| 2280 | ASSERT_TRUE(response1->headers); |
| 2281 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2282 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2283 | |
| 2284 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2285 | // response body. |
| 2286 | trans1.reset(); |
| 2287 | |
| 2288 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2289 | // socket can't be reused, rather than returning it to the socket pool. |
| 2290 | base::RunLoop().RunUntilIdle(); |
| 2291 | |
| 2292 | // There should be no idle sockets in the pool. |
| 2293 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2294 | } |
| 2295 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2296 | // Test the request-challenge-retry sequence for basic auth. |
| 2297 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2298 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2299 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2300 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2301 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2302 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2303 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2304 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2307 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2308 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2309 | MockWrite( |
| 2310 | "GET / HTTP/1.1\r\n" |
| 2311 | "Host: www.example.org\r\n" |
| 2312 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2313 | }; |
| 2314 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2315 | MockRead data_reads1[] = { |
| 2316 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2317 | // Give a couple authenticate options (only the middle one is actually |
| 2318 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2319 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2320 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2321 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2322 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2323 | // Large content-length -- won't matter, as connection will be reset. |
| 2324 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2325 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2326 | }; |
| 2327 | |
| 2328 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2329 | // be issuing -- the final header line contains the credentials. |
| 2330 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2331 | MockWrite( |
| 2332 | "GET / HTTP/1.1\r\n" |
| 2333 | "Host: www.example.org\r\n" |
| 2334 | "Connection: keep-alive\r\n" |
| 2335 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2336 | }; |
| 2337 | |
| 2338 | // Lastly, the server responds with the actual content. |
| 2339 | MockRead data_reads2[] = { |
| 2340 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2341 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2342 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2343 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2344 | }; |
| 2345 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2346 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2347 | data_writes1, arraysize(data_writes1)); |
| 2348 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2349 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2350 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2351 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2353 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2354 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2355 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2357 | |
| 2358 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2360 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2361 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2362 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2363 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2364 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2365 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2366 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2367 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2368 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2370 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2371 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2372 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2374 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2376 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2378 | |
| 2379 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2381 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2382 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2383 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2384 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2385 | // The load timing after restart should have a new socket ID, and times after |
| 2386 | // those of the first load timing. |
| 2387 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2388 | load_timing_info2.connect_timing.connect_start); |
| 2389 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2390 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2391 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2392 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2393 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2394 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2396 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2397 | ASSERT_TRUE(response); |
| 2398 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2399 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2400 | } |
| 2401 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2402 | // Test the request-challenge-retry sequence for basic auth. |
| 2403 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2404 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2405 | HttpRequestInfo request; |
| 2406 | request.method = "GET"; |
| 2407 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2408 | |
| 2409 | TestNetLog log; |
| 2410 | MockHostResolver* resolver = new MockHostResolver(); |
| 2411 | session_deps_.net_log = &log; |
| 2412 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2413 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2415 | |
| 2416 | resolver->rules()->ClearRules(); |
| 2417 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2418 | |
| 2419 | MockWrite data_writes1[] = { |
| 2420 | MockWrite("GET / HTTP/1.1\r\n" |
| 2421 | "Host: www.example.org\r\n" |
| 2422 | "Connection: keep-alive\r\n\r\n"), |
| 2423 | }; |
| 2424 | |
| 2425 | MockRead data_reads1[] = { |
| 2426 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2427 | // Give a couple authenticate options (only the middle one is actually |
| 2428 | // supported). |
| 2429 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2430 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2431 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2433 | // Large content-length -- won't matter, as connection will be reset. |
| 2434 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2435 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2436 | }; |
| 2437 | |
| 2438 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2439 | // be issuing -- the final header line contains the credentials. |
| 2440 | MockWrite data_writes2[] = { |
| 2441 | MockWrite("GET / HTTP/1.1\r\n" |
| 2442 | "Host: www.example.org\r\n" |
| 2443 | "Connection: keep-alive\r\n" |
| 2444 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2445 | }; |
| 2446 | |
| 2447 | // Lastly, the server responds with the actual content. |
| 2448 | MockRead data_reads2[] = { |
| 2449 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2450 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2451 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2452 | }; |
| 2453 | |
| 2454 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2455 | data_writes1, arraysize(data_writes1)); |
| 2456 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2457 | data_writes2, arraysize(data_writes2)); |
| 2458 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2459 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2460 | |
| 2461 | TestCompletionCallback callback1; |
| 2462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2463 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2464 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2465 | |
| 2466 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2467 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2468 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2469 | |
| 2470 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2471 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2472 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2473 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2475 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2476 | ASSERT_TRUE(response); |
| 2477 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2478 | |
| 2479 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2480 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2481 | ASSERT_FALSE(endpoint.address().empty()); |
| 2482 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2483 | |
| 2484 | resolver->rules()->ClearRules(); |
| 2485 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2486 | |
| 2487 | TestCompletionCallback callback2; |
| 2488 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2489 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2490 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2491 | |
| 2492 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2493 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2494 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2495 | // The load timing after restart should have a new socket ID, and times after |
| 2496 | // those of the first load timing. |
| 2497 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2498 | load_timing_info2.connect_timing.connect_start); |
| 2499 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2500 | |
| 2501 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2502 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2503 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2504 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2506 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2507 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2508 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2509 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2511 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2512 | ASSERT_FALSE(endpoint.address().empty()); |
| 2513 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2514 | } |
| 2515 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2516 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2517 | HttpRequestInfo request; |
| 2518 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2519 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2520 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2521 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2524 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2525 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2526 | MockWrite( |
| 2527 | "GET / HTTP/1.1\r\n" |
| 2528 | "Host: www.example.org\r\n" |
| 2529 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2530 | }; |
| 2531 | |
| 2532 | MockRead data_reads[] = { |
| 2533 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2534 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2535 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2536 | // Large content-length -- won't matter, as connection will be reset. |
| 2537 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2538 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2539 | }; |
| 2540 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2541 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2542 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2543 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2544 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2546 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2548 | |
| 2549 | rv = callback.WaitForResult(); |
| 2550 | EXPECT_EQ(0, rv); |
| 2551 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2552 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2553 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2554 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2555 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2558 | ASSERT_TRUE(response); |
| 2559 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2560 | } |
| 2561 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2562 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2563 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2564 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2565 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2566 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2567 | // reused. See http://crbug.com/544255. |
| 2568 | for (int i = 0; i < 2; ++i) { |
| 2569 | HttpRequestInfo request; |
| 2570 | request.method = "GET"; |
| 2571 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2572 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2573 | TestNetLog log; |
| 2574 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2576 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2577 | MockWrite data_writes[] = { |
| 2578 | MockWrite(ASYNC, 0, |
| 2579 | "GET / HTTP/1.1\r\n" |
| 2580 | "Host: www.example.org\r\n" |
| 2581 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2583 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2584 | // be issuing -- the final header line contains the credentials. |
| 2585 | MockWrite(ASYNC, 6, |
| 2586 | "GET / HTTP/1.1\r\n" |
| 2587 | "Host: www.example.org\r\n" |
| 2588 | "Connection: keep-alive\r\n" |
| 2589 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2590 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2591 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2592 | MockRead data_reads[] = { |
| 2593 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2594 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2595 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2596 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2597 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2598 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2599 | // Lastly, the server responds with the actual content. |
| 2600 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2601 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2602 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2603 | MockRead(ASYNC, 10, "Hello"), |
| 2604 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2605 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2606 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2607 | arraysize(data_writes)); |
| 2608 | data.set_busy_before_sync_reads(true); |
| 2609 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2610 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2611 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2614 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2615 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2616 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2617 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2618 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2619 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2620 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2621 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2622 | ASSERT_TRUE(response); |
| 2623 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2624 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2625 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2626 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2627 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2628 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2629 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2630 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2631 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2632 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2633 | TestLoadTimingReused(load_timing_info2); |
| 2634 | // The load timing after restart should have the same socket ID, and times |
| 2635 | // those of the first load timing. |
| 2636 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2637 | load_timing_info2.send_start); |
| 2638 | 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] | 2639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2640 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2641 | ASSERT_TRUE(response); |
| 2642 | EXPECT_FALSE(response->auth_challenge); |
| 2643 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2644 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2645 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2646 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2647 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2648 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2649 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2650 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2651 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2652 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2656 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2657 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2658 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2660 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2663 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2664 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2665 | MockWrite("GET / HTTP/1.1\r\n" |
| 2666 | "Host: www.example.org\r\n" |
| 2667 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2670 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2671 | MockWrite("GET / HTTP/1.1\r\n" |
| 2672 | "Host: www.example.org\r\n" |
| 2673 | "Connection: keep-alive\r\n" |
| 2674 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2675 | }; |
| 2676 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2677 | MockRead data_reads1[] = { |
| 2678 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2679 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2680 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2681 | |
| 2682 | // Lastly, the server responds with the actual content. |
| 2683 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2684 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2685 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2686 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2687 | }; |
| 2688 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2689 | // An incorrect reconnect would cause this to be read. |
| 2690 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2691 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2692 | }; |
| 2693 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2694 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2695 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2696 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2697 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2701 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2704 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2706 | |
| 2707 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2708 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2710 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2711 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2712 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2714 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2716 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
| 2719 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2722 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2723 | ASSERT_TRUE(response); |
| 2724 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2725 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2729 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2730 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2731 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2736 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2737 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2738 | MockWrite("GET / HTTP/1.1\r\n" |
| 2739 | "Host: www.example.org\r\n" |
| 2740 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2742 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2743 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2744 | MockWrite("GET / HTTP/1.1\r\n" |
| 2745 | "Host: www.example.org\r\n" |
| 2746 | "Connection: keep-alive\r\n" |
| 2747 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2748 | }; |
| 2749 | |
| 2750 | // Respond with 5 kb of response body. |
| 2751 | std::string large_body_string("Unauthorized"); |
| 2752 | large_body_string.append(5 * 1024, ' '); |
| 2753 | large_body_string.append("\r\n"); |
| 2754 | |
| 2755 | MockRead data_reads1[] = { |
| 2756 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2757 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2758 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2759 | // 5134 = 12 + 5 * 1024 + 2 |
| 2760 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2761 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2762 | |
| 2763 | // Lastly, the server responds with the actual content. |
| 2764 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2765 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2766 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2767 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2768 | }; |
| 2769 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2770 | // An incorrect reconnect would cause this to be read. |
| 2771 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2772 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2773 | }; |
| 2774 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2775 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2776 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2777 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2778 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2779 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2780 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2781 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2782 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2785 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2787 | |
| 2788 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2789 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2790 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2791 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2792 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2793 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2795 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | |
| 2800 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2803 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2804 | ASSERT_TRUE(response); |
| 2805 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2806 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2810 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2811 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2812 | HttpRequestInfo request; |
| 2813 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2814 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2817 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2818 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2819 | MockWrite( |
| 2820 | "GET / HTTP/1.1\r\n" |
| 2821 | "Host: www.example.org\r\n" |
| 2822 | "Connection: keep-alive\r\n\r\n"), |
| 2823 | // This simulates the seemingly successful write to a closed connection |
| 2824 | // if the bug is not fixed. |
| 2825 | MockWrite( |
| 2826 | "GET / HTTP/1.1\r\n" |
| 2827 | "Host: www.example.org\r\n" |
| 2828 | "Connection: keep-alive\r\n" |
| 2829 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2830 | }; |
| 2831 | |
| 2832 | MockRead data_reads1[] = { |
| 2833 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2834 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2835 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2836 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2837 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2838 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2839 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2840 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2841 | }; |
| 2842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2843 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2844 | // be issuing -- the final header line contains the credentials. |
| 2845 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2846 | MockWrite( |
| 2847 | "GET / HTTP/1.1\r\n" |
| 2848 | "Host: www.example.org\r\n" |
| 2849 | "Connection: keep-alive\r\n" |
| 2850 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2851 | }; |
| 2852 | |
| 2853 | // Lastly, the server responds with the actual content. |
| 2854 | MockRead data_reads2[] = { |
| 2855 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2857 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2858 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2859 | }; |
| 2860 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2861 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2862 | data_writes1, arraysize(data_writes1)); |
| 2863 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2864 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2865 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2866 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2867 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2868 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2871 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2873 | |
| 2874 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2877 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2878 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2879 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2881 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2883 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2885 | |
| 2886 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2890 | ASSERT_TRUE(response); |
| 2891 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2892 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2893 | } |
| 2894 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2895 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2896 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2897 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2898 | HttpRequestInfo request; |
| 2899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2900 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2901 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2902 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2903 | |
| 2904 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2905 | session_deps_.proxy_service = |
| 2906 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2907 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2908 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2910 | |
| 2911 | // Since we have proxy, should try to establish tunnel. |
| 2912 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2913 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2914 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2915 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2916 | }; |
| 2917 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2918 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2919 | // connection. |
| 2920 | MockRead data_reads1[] = { |
| 2921 | // No credentials. |
| 2922 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2923 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2924 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2925 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2926 | // Since the first connection couldn't be reused, need to establish another |
| 2927 | // once given credentials. |
| 2928 | MockWrite data_writes2[] = { |
| 2929 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2930 | // be issuing -- the final header line contains the credentials. |
| 2931 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2932 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2933 | "Proxy-Connection: keep-alive\r\n" |
| 2934 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2935 | |
| 2936 | MockWrite("GET / HTTP/1.1\r\n" |
| 2937 | "Host: www.example.org\r\n" |
| 2938 | "Connection: keep-alive\r\n\r\n"), |
| 2939 | }; |
| 2940 | |
| 2941 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2942 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2943 | |
| 2944 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2945 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2946 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2947 | MockRead(SYNCHRONOUS, "hello"), |
| 2948 | }; |
| 2949 | |
| 2950 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2951 | data_writes1, arraysize(data_writes1)); |
| 2952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2953 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2954 | data_writes2, arraysize(data_writes2)); |
| 2955 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2956 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2958 | |
| 2959 | TestCompletionCallback callback1; |
| 2960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2961 | std::unique_ptr<HttpNetworkTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2962 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2963 | |
| 2964 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2966 | |
| 2967 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2968 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2969 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2970 | log.GetEntries(&entries); |
| 2971 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2972 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2973 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2974 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2975 | entries, pos, |
| 2976 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2977 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2978 | |
| 2979 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2980 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2981 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2982 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2983 | EXPECT_EQ(407, response->headers->response_code()); |
| 2984 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2985 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2986 | |
| 2987 | LoadTimingInfo load_timing_info; |
| 2988 | // CONNECT requests and responses are handled at the connect job level, so |
| 2989 | // the transaction does not yet have a connection. |
| 2990 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2991 | |
| 2992 | TestCompletionCallback callback2; |
| 2993 | |
| 2994 | rv = |
| 2995 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2997 | |
| 2998 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2999 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3000 | |
| 3001 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3002 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3003 | |
| 3004 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3005 | EXPECT_EQ(200, response->headers->response_code()); |
| 3006 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3007 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3008 | |
| 3009 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3010 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3011 | |
| 3012 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3013 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3014 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3015 | |
| 3016 | trans.reset(); |
| 3017 | session->CloseAllConnections(); |
| 3018 | } |
| 3019 | |
| 3020 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3021 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3022 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3023 | HttpRequestInfo request; |
| 3024 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3025 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3026 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3027 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3028 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3029 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3030 | session_deps_.proxy_service = |
| 3031 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3032 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3033 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3035 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3036 | // Since we have proxy, should try to establish tunnel. |
| 3037 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3038 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3039 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3040 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3041 | }; |
| 3042 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3043 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3044 | // connection. |
| 3045 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3046 | // No credentials. |
| 3047 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3048 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3049 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3050 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3051 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3052 | MockWrite data_writes2[] = { |
| 3053 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3054 | // be issuing -- the final header line contains the credentials. |
| 3055 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3056 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3057 | "Proxy-Connection: keep-alive\r\n" |
| 3058 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3059 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3060 | MockWrite("GET / HTTP/1.1\r\n" |
| 3061 | "Host: www.example.org\r\n" |
| 3062 | "Connection: keep-alive\r\n\r\n"), |
| 3063 | }; |
| 3064 | |
| 3065 | MockRead data_reads2[] = { |
| 3066 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3067 | |
| 3068 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3069 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3070 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3071 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3072 | }; |
| 3073 | |
| 3074 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3075 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3076 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3077 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3078 | data_writes2, arraysize(data_writes2)); |
| 3079 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3080 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3083 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3085 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3088 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3090 | |
| 3091 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3092 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3093 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3094 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3095 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3096 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3097 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3098 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3099 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3100 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3101 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3102 | |
| 3103 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3104 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3105 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3106 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3107 | EXPECT_EQ(407, response->headers->response_code()); |
| 3108 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3109 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3110 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3111 | LoadTimingInfo load_timing_info; |
| 3112 | // CONNECT requests and responses are handled at the connect job level, so |
| 3113 | // the transaction does not yet have a connection. |
| 3114 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3116 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3118 | rv = trans->RestartWithAuth( |
| 3119 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3121 | |
| 3122 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3124 | |
| 3125 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3126 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3127 | |
| 3128 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3129 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3130 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3131 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3132 | |
| 3133 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3134 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3135 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3136 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3137 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3138 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3139 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3140 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3141 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3142 | } |
| 3143 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3144 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3145 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3146 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3147 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3148 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3149 | // reused. See http://crbug.com/544255. |
| 3150 | for (int i = 0; i < 2; ++i) { |
| 3151 | HttpRequestInfo request; |
| 3152 | request.method = "GET"; |
| 3153 | request.url = GURL("https://www.example.org/"); |
| 3154 | // Ensure that proxy authentication is attempted even |
| 3155 | // when the no authentication data flag is set. |
| 3156 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3157 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3158 | // Configure against proxy server "myproxy:70". |
| 3159 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3160 | BoundTestNetLog log; |
| 3161 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3165 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3166 | // Since we have proxy, should try to establish tunnel. |
| 3167 | MockWrite data_writes1[] = { |
| 3168 | MockWrite(ASYNC, 0, |
| 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\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3173 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3174 | // be issuing -- the final header line contains the credentials. |
| 3175 | MockWrite(ASYNC, 3, |
| 3176 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3177 | "Host: www.example.org:443\r\n" |
| 3178 | "Proxy-Connection: keep-alive\r\n" |
| 3179 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3180 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3181 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3182 | // The proxy responds to the connect with a 407, using a persistent |
| 3183 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3184 | MockRead data_reads1[] = { |
| 3185 | // No credentials. |
| 3186 | MockRead(ASYNC, 1, |
| 3187 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3188 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3189 | "Proxy-Connection: keep-alive\r\n" |
| 3190 | "Content-Length: 10\r\n\r\n"), |
| 3191 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3192 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3193 | // Wrong credentials (wrong password). |
| 3194 | MockRead(ASYNC, 4, |
| 3195 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3196 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3197 | "Proxy-Connection: keep-alive\r\n" |
| 3198 | "Content-Length: 10\r\n\r\n"), |
| 3199 | // No response body because the test stops reading here. |
| 3200 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3201 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3202 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3203 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3204 | arraysize(data_writes1)); |
| 3205 | data1.set_busy_before_sync_reads(true); |
| 3206 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3207 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3208 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3210 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3211 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3212 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3213 | TestNetLogEntry::List entries; |
| 3214 | log.GetEntries(&entries); |
| 3215 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3216 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3217 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3218 | ExpectLogContainsSomewhere( |
| 3219 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3220 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3221 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3223 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3224 | ASSERT_TRUE(response); |
| 3225 | ASSERT_TRUE(response->headers); |
| 3226 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3227 | EXPECT_EQ(407, response->headers->response_code()); |
| 3228 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3229 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3230 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3231 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3232 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3233 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3234 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3235 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3236 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3237 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3239 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3240 | ASSERT_TRUE(response); |
| 3241 | ASSERT_TRUE(response->headers); |
| 3242 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3243 | EXPECT_EQ(407, response->headers->response_code()); |
| 3244 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3245 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3246 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3247 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3248 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3249 | // out of scope. |
| 3250 | session->CloseAllConnections(); |
| 3251 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3255 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3256 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3257 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3258 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3259 | // reused. See http://crbug.com/544255. |
| 3260 | for (int i = 0; i < 2; ++i) { |
| 3261 | HttpRequestInfo request; |
| 3262 | request.method = "GET"; |
| 3263 | request.url = GURL("https://www.example.org/"); |
| 3264 | // Ensure that proxy authentication is attempted even |
| 3265 | // when the no authentication data flag is set. |
| 3266 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3267 | |
| 3268 | // Configure against proxy server "myproxy:70". |
| 3269 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3270 | BoundTestNetLog log; |
| 3271 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3272 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3275 | |
| 3276 | // Since we have proxy, should try to establish tunnel. |
| 3277 | MockWrite data_writes1[] = { |
| 3278 | MockWrite(ASYNC, 0, |
| 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\r\n"), |
| 3282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3283 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3284 | // be issuing -- the final header line contains the credentials. |
| 3285 | MockWrite(ASYNC, 3, |
| 3286 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3287 | "Host: www.example.org:443\r\n" |
| 3288 | "Proxy-Connection: keep-alive\r\n" |
| 3289 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3290 | }; |
| 3291 | |
| 3292 | // The proxy responds to the connect with a 407, using a persistent |
| 3293 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3294 | MockRead data_reads1[] = { |
| 3295 | // No credentials. |
| 3296 | MockRead(ASYNC, 1, |
| 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 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3301 | |
| 3302 | // Wrong credentials (wrong password). |
| 3303 | MockRead(ASYNC, 4, |
| 3304 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3305 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3306 | "Content-Length: 10\r\n\r\n"), |
| 3307 | // No response body because the test stops reading here. |
| 3308 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3309 | }; |
| 3310 | |
| 3311 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3312 | arraysize(data_writes1)); |
| 3313 | data1.set_busy_before_sync_reads(true); |
| 3314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3315 | |
| 3316 | TestCompletionCallback callback1; |
| 3317 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3318 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3319 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3320 | |
| 3321 | TestNetLogEntry::List entries; |
| 3322 | log.GetEntries(&entries); |
| 3323 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3324 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3325 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3326 | ExpectLogContainsSomewhere( |
| 3327 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3328 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3329 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | ASSERT_TRUE(response); |
| 3333 | ASSERT_TRUE(response->headers); |
| 3334 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3335 | EXPECT_EQ(407, response->headers->response_code()); |
| 3336 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3337 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3338 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3339 | |
| 3340 | TestCompletionCallback callback2; |
| 3341 | |
| 3342 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3343 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3344 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3345 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3347 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3348 | ASSERT_TRUE(response); |
| 3349 | ASSERT_TRUE(response->headers); |
| 3350 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3351 | EXPECT_EQ(407, response->headers->response_code()); |
| 3352 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3353 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3354 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3355 | |
| 3356 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3357 | // out of scope. |
| 3358 | session->CloseAllConnections(); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3363 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3364 | // the case the server sends extra data on the original socket, so it can't be |
| 3365 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3366 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3367 | HttpRequestInfo request; |
| 3368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3369 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3370 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3371 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3372 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3373 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3374 | session_deps_.proxy_service = |
| 3375 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3376 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3377 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3379 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3380 | // Since we have proxy, should try to establish tunnel. |
| 3381 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3382 | MockWrite(ASYNC, 0, |
| 3383 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3384 | "Host: www.example.org:443\r\n" |
| 3385 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3386 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3387 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3388 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3389 | // extra data, so the socket cannot be reused. |
| 3390 | MockRead data_reads1[] = { |
| 3391 | // No credentials. |
| 3392 | MockRead(ASYNC, 1, |
| 3393 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3394 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3395 | "Content-Length: 10\r\n\r\n"), |
| 3396 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3397 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3398 | }; |
| 3399 | |
| 3400 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3401 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3402 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3403 | MockWrite(ASYNC, 0, |
| 3404 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3405 | "Host: www.example.org:443\r\n" |
| 3406 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3407 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3408 | |
| 3409 | MockWrite(ASYNC, 2, |
| 3410 | "GET / HTTP/1.1\r\n" |
| 3411 | "Host: www.example.org\r\n" |
| 3412 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3413 | }; |
| 3414 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | MockRead data_reads2[] = { |
| 3416 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3417 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3418 | MockRead(ASYNC, 3, |
| 3419 | "HTTP/1.1 200 OK\r\n" |
| 3420 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3421 | "Content-Length: 5\r\n\r\n"), |
| 3422 | // No response body because the test stops reading here. |
| 3423 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3424 | }; |
| 3425 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3426 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3427 | arraysize(data_writes1)); |
| 3428 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3429 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3430 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3431 | arraysize(data_writes2)); |
| 3432 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3433 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3436 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3438 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3439 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3440 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3441 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3442 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3443 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3444 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3445 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3446 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3447 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3448 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3449 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3450 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3451 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3452 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3453 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3454 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3455 | ASSERT_TRUE(response); |
| 3456 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3457 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3458 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3459 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3460 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3461 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3462 | LoadTimingInfo load_timing_info; |
| 3463 | // CONNECT requests and responses are handled at the connect job level, so |
| 3464 | // the transaction does not yet have a connection. |
| 3465 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3467 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3468 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3469 | rv = |
| 3470 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3471 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3472 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3473 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3474 | EXPECT_EQ(200, response->headers->response_code()); |
| 3475 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3476 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3477 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3478 | // The password prompt info should not be set. |
| 3479 | EXPECT_FALSE(response->auth_challenge); |
| 3480 | |
| 3481 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3482 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3483 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3484 | |
| 3485 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3486 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3487 | } |
| 3488 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3489 | // Test the case a proxy closes a socket while the challenge body is being |
| 3490 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3491 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3492 | HttpRequestInfo request; |
| 3493 | request.method = "GET"; |
| 3494 | request.url = GURL("https://www.example.org/"); |
| 3495 | // Ensure that proxy authentication is attempted even |
| 3496 | // when the no authentication data flag is set. |
| 3497 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3498 | |
| 3499 | // Configure against proxy server "myproxy:70". |
| 3500 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3501 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3504 | |
| 3505 | // Since we have proxy, should try to establish tunnel. |
| 3506 | MockWrite data_writes1[] = { |
| 3507 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3508 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3509 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3510 | }; |
| 3511 | |
| 3512 | // The proxy responds to the connect with a 407, using a persistent |
| 3513 | // connection. |
| 3514 | MockRead data_reads1[] = { |
| 3515 | // No credentials. |
| 3516 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3517 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3518 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3519 | // Server hands up in the middle of the body. |
| 3520 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3521 | }; |
| 3522 | |
| 3523 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3524 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3525 | // be issuing -- the final header line contains the credentials. |
| 3526 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3527 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3528 | "Proxy-Connection: keep-alive\r\n" |
| 3529 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3530 | |
| 3531 | MockWrite("GET / HTTP/1.1\r\n" |
| 3532 | "Host: www.example.org\r\n" |
| 3533 | "Connection: keep-alive\r\n\r\n"), |
| 3534 | }; |
| 3535 | |
| 3536 | MockRead data_reads2[] = { |
| 3537 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3538 | |
| 3539 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3540 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3541 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3542 | MockRead(SYNCHRONOUS, "hello"), |
| 3543 | }; |
| 3544 | |
| 3545 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3546 | data_writes1, arraysize(data_writes1)); |
| 3547 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3548 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3549 | data_writes2, arraysize(data_writes2)); |
| 3550 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3551 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3553 | |
| 3554 | TestCompletionCallback callback; |
| 3555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3557 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3559 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3560 | ASSERT_TRUE(response); |
| 3561 | ASSERT_TRUE(response->headers); |
| 3562 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3563 | EXPECT_EQ(407, response->headers->response_code()); |
| 3564 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3566 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3567 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3568 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3569 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3570 | ASSERT_TRUE(response); |
| 3571 | ASSERT_TRUE(response->headers); |
| 3572 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3573 | EXPECT_EQ(200, response->headers->response_code()); |
| 3574 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3575 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3576 | EXPECT_EQ("hello", body); |
| 3577 | } |
| 3578 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3579 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3580 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3581 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3582 | HttpRequestInfo request; |
| 3583 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3584 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3585 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3586 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3587 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3588 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3592 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3593 | // Since we have proxy, should try to establish tunnel. |
| 3594 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3595 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3596 | "Host: www.example.org:443\r\n" |
| 3597 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3598 | }; |
| 3599 | |
| 3600 | // The proxy responds to the connect with a 407. |
| 3601 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3602 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3603 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3604 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3606 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3607 | }; |
| 3608 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3609 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3610 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3613 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3617 | |
| 3618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3619 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3620 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3621 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3622 | ASSERT_TRUE(response); |
| 3623 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3624 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3625 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3626 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3627 | |
| 3628 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3629 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3630 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3631 | |
| 3632 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3633 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3634 | } |
| 3635 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3636 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3637 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3638 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3639 | HttpRequestInfo request; |
| 3640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3641 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3642 | |
| 3643 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3644 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3648 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3649 | |
| 3650 | // Since we have proxy, should try to establish tunnel. |
| 3651 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3652 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3653 | "Host: www.example.org:443\r\n" |
| 3654 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3655 | }; |
| 3656 | |
| 3657 | // The proxy responds to the connect with a 407. |
| 3658 | MockRead data_reads[] = { |
| 3659 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3660 | MockRead("X-Foo: bar\r\n"), |
| 3661 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3662 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3663 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3664 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3665 | }; |
| 3666 | |
| 3667 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3668 | arraysize(data_writes)); |
| 3669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3670 | |
| 3671 | TestCompletionCallback callback; |
| 3672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3673 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3675 | |
| 3676 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3677 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3679 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3680 | ASSERT_TRUE(response); |
| 3681 | ASSERT_TRUE(response->headers); |
| 3682 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3683 | EXPECT_EQ(407, response->headers->response_code()); |
| 3684 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3685 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3686 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3687 | |
| 3688 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3689 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3690 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3691 | |
| 3692 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3693 | session->CloseAllConnections(); |
| 3694 | } |
| 3695 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3696 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3697 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3698 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3699 | HttpRequestInfo request; |
| 3700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3701 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3702 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3703 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3706 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3707 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3708 | MockWrite( |
| 3709 | "GET / HTTP/1.1\r\n" |
| 3710 | "Host: www.example.org\r\n" |
| 3711 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3712 | }; |
| 3713 | |
| 3714 | MockRead data_reads1[] = { |
| 3715 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3716 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3717 | // Large content-length -- won't matter, as connection will be reset. |
| 3718 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3719 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3720 | }; |
| 3721 | |
| 3722 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3723 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3726 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3727 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3728 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3730 | |
| 3731 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3732 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3733 | } |
| 3734 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3735 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3736 | // through a non-authenticating proxy. The request should fail with |
| 3737 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3738 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3739 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3740 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3741 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3742 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3743 | HttpRequestInfo request; |
| 3744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3745 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3746 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3747 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3748 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3749 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3750 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3751 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3752 | // Since we have proxy, should try to establish tunnel. |
| 3753 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3754 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3755 | "Host: www.example.org:443\r\n" |
| 3756 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3757 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3758 | MockWrite("GET / HTTP/1.1\r\n" |
| 3759 | "Host: www.example.org\r\n" |
| 3760 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3761 | }; |
| 3762 | |
| 3763 | MockRead data_reads1[] = { |
| 3764 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3765 | |
| 3766 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3767 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3768 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3770 | }; |
| 3771 | |
| 3772 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3773 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3774 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3775 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3778 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3782 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3784 | |
| 3785 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3786 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3787 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3788 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3789 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3790 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3791 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3792 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3793 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3794 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3795 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3796 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3797 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3798 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3799 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3800 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3801 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3802 | HttpRequestInfo request; |
| 3803 | request.method = "GET"; |
| 3804 | request.url = GURL("https://www.example.org/"); |
| 3805 | |
| 3806 | // Configure against proxy server "myproxy:70". |
| 3807 | session_deps_.proxy_service = |
| 3808 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3810 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3811 | new HttpAuthHandlerMock::Factory()); |
| 3812 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3813 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3814 | mock_handler->set_allows_default_credentials(true); |
| 3815 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3816 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3817 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3818 | |
| 3819 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3820 | NetLog net_log; |
| 3821 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3822 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3823 | |
| 3824 | // Since we have proxy, should try to establish tunnel. |
| 3825 | MockWrite data_writes1[] = { |
| 3826 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3827 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3828 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3829 | }; |
| 3830 | |
| 3831 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3832 | // connection. |
| 3833 | MockRead data_reads1[] = { |
| 3834 | // No credentials. |
| 3835 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3836 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3837 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3838 | }; |
| 3839 | |
| 3840 | // Since the first connection couldn't be reused, need to establish another |
| 3841 | // once given credentials. |
| 3842 | MockWrite data_writes2[] = { |
| 3843 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3844 | // be issuing -- the final header line contains the credentials. |
| 3845 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3846 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3847 | "Proxy-Connection: keep-alive\r\n" |
| 3848 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3849 | |
| 3850 | MockWrite("GET / HTTP/1.1\r\n" |
| 3851 | "Host: www.example.org\r\n" |
| 3852 | "Connection: keep-alive\r\n\r\n"), |
| 3853 | }; |
| 3854 | |
| 3855 | MockRead data_reads2[] = { |
| 3856 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3857 | |
| 3858 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3859 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3860 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3861 | MockRead(SYNCHRONOUS, "hello"), |
| 3862 | }; |
| 3863 | |
| 3864 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3865 | data_writes1, arraysize(data_writes1)); |
| 3866 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3867 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3868 | data_writes2, arraysize(data_writes2)); |
| 3869 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3870 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3873 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3874 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3875 | |
| 3876 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3877 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3878 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3879 | |
| 3880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3881 | ASSERT_TRUE(response); |
| 3882 | ASSERT_TRUE(response->headers); |
| 3883 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3884 | EXPECT_EQ(407, response->headers->response_code()); |
| 3885 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3886 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3887 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3888 | |
| 3889 | LoadTimingInfo load_timing_info; |
| 3890 | // CONNECT requests and responses are handled at the connect job level, so |
| 3891 | // the transaction does not yet have a connection. |
| 3892 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3893 | |
| 3894 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3895 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3896 | response = trans->GetResponseInfo(); |
| 3897 | ASSERT_TRUE(response); |
| 3898 | ASSERT_TRUE(response->headers); |
| 3899 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3900 | EXPECT_EQ(200, response->headers->response_code()); |
| 3901 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3902 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3903 | |
| 3904 | // The password prompt info should not be set. |
| 3905 | EXPECT_FALSE(response->auth_challenge); |
| 3906 | |
| 3907 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3908 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3909 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3910 | |
| 3911 | trans.reset(); |
| 3912 | session->CloseAllConnections(); |
| 3913 | } |
| 3914 | |
| 3915 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3916 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3917 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3918 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3919 | HttpRequestInfo request; |
| 3920 | request.method = "GET"; |
| 3921 | request.url = GURL("https://www.example.org/"); |
| 3922 | |
| 3923 | // Configure against proxy server "myproxy:70". |
| 3924 | session_deps_.proxy_service = |
| 3925 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3927 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3928 | new HttpAuthHandlerMock::Factory()); |
| 3929 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3930 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3931 | mock_handler->set_allows_default_credentials(true); |
| 3932 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3933 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3934 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3935 | |
| 3936 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3937 | NetLog net_log; |
| 3938 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3939 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | |
| 3941 | // Should try to establish tunnel. |
| 3942 | MockWrite data_writes1[] = { |
| 3943 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3944 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3945 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3946 | |
| 3947 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3948 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3949 | "Proxy-Connection: keep-alive\r\n" |
| 3950 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3951 | }; |
| 3952 | |
| 3953 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3954 | // connection. |
| 3955 | MockRead data_reads1[] = { |
| 3956 | // No credentials. |
| 3957 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3958 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3959 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3960 | }; |
| 3961 | |
| 3962 | // Since the first connection was closed, need to establish another once given |
| 3963 | // credentials. |
| 3964 | MockWrite data_writes2[] = { |
| 3965 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3966 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3967 | "Proxy-Connection: keep-alive\r\n" |
| 3968 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3969 | |
| 3970 | MockWrite("GET / HTTP/1.1\r\n" |
| 3971 | "Host: www.example.org\r\n" |
| 3972 | "Connection: keep-alive\r\n\r\n"), |
| 3973 | }; |
| 3974 | |
| 3975 | MockRead data_reads2[] = { |
| 3976 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3977 | |
| 3978 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3979 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3980 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3981 | MockRead(SYNCHRONOUS, "hello"), |
| 3982 | }; |
| 3983 | |
| 3984 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3985 | data_writes1, arraysize(data_writes1)); |
| 3986 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3987 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3988 | data_writes2, arraysize(data_writes2)); |
| 3989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3990 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3993 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3994 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3995 | |
| 3996 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3997 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3998 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3999 | |
| 4000 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4001 | ASSERT_TRUE(response); |
| 4002 | ASSERT_TRUE(response->headers); |
| 4003 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4004 | EXPECT_EQ(407, response->headers->response_code()); |
| 4005 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4006 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4007 | EXPECT_FALSE(response->auth_challenge); |
| 4008 | |
| 4009 | LoadTimingInfo load_timing_info; |
| 4010 | // CONNECT requests and responses are handled at the connect job level, so |
| 4011 | // the transaction does not yet have a connection. |
| 4012 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4013 | |
| 4014 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4015 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4016 | |
| 4017 | response = trans->GetResponseInfo(); |
| 4018 | ASSERT_TRUE(response); |
| 4019 | ASSERT_TRUE(response->headers); |
| 4020 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4021 | EXPECT_EQ(200, response->headers->response_code()); |
| 4022 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4023 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4024 | |
| 4025 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4026 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4027 | |
| 4028 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4029 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4030 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4031 | |
| 4032 | trans.reset(); |
| 4033 | session->CloseAllConnections(); |
| 4034 | } |
| 4035 | |
| 4036 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4037 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4038 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4039 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4040 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4041 | HttpRequestInfo request; |
| 4042 | request.method = "GET"; |
| 4043 | request.url = GURL("https://www.example.org/"); |
| 4044 | |
| 4045 | // Configure against proxy server "myproxy:70". |
| 4046 | session_deps_.proxy_service = |
| 4047 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4048 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4049 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4050 | new HttpAuthHandlerMock::Factory()); |
| 4051 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4052 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4053 | mock_handler->set_allows_default_credentials(true); |
| 4054 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4055 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4056 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4057 | |
| 4058 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4059 | NetLog net_log; |
| 4060 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4061 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | |
| 4063 | // Should try to establish tunnel. |
| 4064 | MockWrite data_writes1[] = { |
| 4065 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4066 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4067 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4068 | |
| 4069 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4070 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4071 | "Proxy-Connection: keep-alive\r\n" |
| 4072 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4073 | }; |
| 4074 | |
| 4075 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4076 | // second request is sent. |
| 4077 | MockRead data_reads1[] = { |
| 4078 | // No credentials. |
| 4079 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4080 | MockRead("Content-Length: 0\r\n"), |
| 4081 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4082 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4083 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4084 | }; |
| 4085 | |
| 4086 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4087 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4088 | // request. |
| 4089 | MockWrite data_writes2[] = { |
| 4090 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4091 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4092 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4093 | }; |
| 4094 | |
| 4095 | // The proxy, having had more than enough of us, just hangs up. |
| 4096 | MockRead data_reads2[] = { |
| 4097 | // No credentials. |
| 4098 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4099 | }; |
| 4100 | |
| 4101 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4102 | data_writes1, arraysize(data_writes1)); |
| 4103 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4104 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4105 | data_writes2, arraysize(data_writes2)); |
| 4106 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4108 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4109 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4110 | |
| 4111 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4112 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4113 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4114 | |
| 4115 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4116 | ASSERT_TRUE(response); |
| 4117 | ASSERT_TRUE(response->headers); |
| 4118 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4119 | EXPECT_EQ(407, response->headers->response_code()); |
| 4120 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4121 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4122 | EXPECT_FALSE(response->auth_challenge); |
| 4123 | |
| 4124 | LoadTimingInfo load_timing_info; |
| 4125 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4126 | |
| 4127 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4128 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4129 | |
| 4130 | trans.reset(); |
| 4131 | session->CloseAllConnections(); |
| 4132 | } |
| 4133 | |
| 4134 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4135 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4136 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4137 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4138 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4139 | HttpRequestInfo request; |
| 4140 | request.method = "GET"; |
| 4141 | request.url = GURL("https://www.example.org/"); |
| 4142 | |
| 4143 | // Configure against proxy server "myproxy:70". |
| 4144 | session_deps_.proxy_service = |
| 4145 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4146 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4147 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4148 | new HttpAuthHandlerMock::Factory()); |
| 4149 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4150 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | mock_handler->set_allows_default_credentials(true); |
| 4152 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4153 | HttpAuth::AUTH_PROXY); |
| 4154 | // Add another handler for the second challenge. It supports default |
| 4155 | // credentials, but they shouldn't be used, since they were already tried. |
| 4156 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4157 | mock_handler->set_allows_default_credentials(true); |
| 4158 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4159 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4160 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4161 | |
| 4162 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4163 | NetLog net_log; |
| 4164 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4165 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4166 | |
| 4167 | // Should try to establish tunnel. |
| 4168 | MockWrite data_writes1[] = { |
| 4169 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4170 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4171 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4172 | }; |
| 4173 | |
| 4174 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4175 | // connection. |
| 4176 | MockRead data_reads1[] = { |
| 4177 | // No credentials. |
| 4178 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4179 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4180 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4181 | }; |
| 4182 | |
| 4183 | // Since the first connection was closed, need to establish another once given |
| 4184 | // credentials. |
| 4185 | MockWrite data_writes2[] = { |
| 4186 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4187 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4188 | "Proxy-Connection: keep-alive\r\n" |
| 4189 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4190 | }; |
| 4191 | |
| 4192 | MockRead data_reads2[] = { |
| 4193 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4194 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4195 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4196 | }; |
| 4197 | |
| 4198 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4199 | data_writes1, arraysize(data_writes1)); |
| 4200 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4201 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4202 | data_writes2, arraysize(data_writes2)); |
| 4203 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4204 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4207 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4209 | |
| 4210 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4211 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4212 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4213 | |
| 4214 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4215 | ASSERT_TRUE(response); |
| 4216 | ASSERT_TRUE(response->headers); |
| 4217 | EXPECT_EQ(407, response->headers->response_code()); |
| 4218 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4219 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4220 | EXPECT_FALSE(response->auth_challenge); |
| 4221 | |
| 4222 | LoadTimingInfo load_timing_info; |
| 4223 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4224 | |
| 4225 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4226 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4227 | response = trans->GetResponseInfo(); |
| 4228 | ASSERT_TRUE(response); |
| 4229 | ASSERT_TRUE(response->headers); |
| 4230 | EXPECT_EQ(407, response->headers->response_code()); |
| 4231 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4232 | EXPECT_TRUE(response->auth_challenge); |
| 4233 | |
| 4234 | trans.reset(); |
| 4235 | session->CloseAllConnections(); |
| 4236 | } |
| 4237 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4238 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4239 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4240 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4241 | // authentication handshake can continue with the same scheme but with a |
| 4242 | // different identity. |
| 4243 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4244 | HttpRequestInfo request; |
| 4245 | request.method = "GET"; |
| 4246 | request.url = GURL("http://www.example.org/"); |
| 4247 | |
| 4248 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 4249 | new HttpAuthHandlerMock::Factory()); |
| 4250 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4251 | |
| 4252 | // First handler. Uses default credentials, but barfs at generate auth token. |
| 4253 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 4254 | mock_handler->set_allows_default_credentials(true); |
| 4255 | mock_handler->set_allows_explicit_credentials(true); |
| 4256 | mock_handler->set_connection_based(true); |
| 4257 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4258 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4259 | HttpAuth::AUTH_SERVER); |
| 4260 | |
| 4261 | // Add another handler for the second challenge. It supports default |
| 4262 | // credentials, but they shouldn't be used, since they were already tried. |
| 4263 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4264 | mock_handler->set_allows_default_credentials(true); |
| 4265 | mock_handler->set_allows_explicit_credentials(true); |
| 4266 | mock_handler->set_connection_based(true); |
| 4267 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4268 | HttpAuth::AUTH_SERVER); |
| 4269 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4270 | |
| 4271 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4272 | |
| 4273 | MockWrite data_writes1[] = { |
| 4274 | MockWrite("GET / HTTP/1.1\r\n" |
| 4275 | "Host: www.example.org\r\n" |
| 4276 | "Connection: keep-alive\r\n\r\n"), |
| 4277 | }; |
| 4278 | |
| 4279 | MockRead data_reads1[] = { |
| 4280 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4281 | "WWW-Authenticate: Mock\r\n" |
| 4282 | "Connection: keep-alive\r\n\r\n"), |
| 4283 | }; |
| 4284 | |
| 4285 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4286 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4287 | // transaction procceds without an authorization header. |
| 4288 | MockWrite data_writes2[] = { |
| 4289 | MockWrite("GET / HTTP/1.1\r\n" |
| 4290 | "Host: www.example.org\r\n" |
| 4291 | "Connection: keep-alive\r\n\r\n"), |
| 4292 | }; |
| 4293 | |
| 4294 | MockRead data_reads2[] = { |
| 4295 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4296 | "WWW-Authenticate: Mock\r\n" |
| 4297 | "Connection: keep-alive\r\n\r\n"), |
| 4298 | }; |
| 4299 | |
| 4300 | MockWrite data_writes3[] = { |
| 4301 | MockWrite("GET / HTTP/1.1\r\n" |
| 4302 | "Host: www.example.org\r\n" |
| 4303 | "Connection: keep-alive\r\n" |
| 4304 | "Authorization: auth_token\r\n\r\n"), |
| 4305 | }; |
| 4306 | |
| 4307 | MockRead data_reads3[] = { |
| 4308 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4309 | "Content-Length: 5\r\n" |
| 4310 | "Content-Type: text/plain\r\n" |
| 4311 | "Connection: keep-alive\r\n\r\n" |
| 4312 | "Hello"), |
| 4313 | }; |
| 4314 | |
| 4315 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4316 | data_writes1, arraysize(data_writes1)); |
| 4317 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4318 | |
| 4319 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4320 | data_writes2, arraysize(data_writes2)); |
| 4321 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4322 | |
| 4323 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4324 | data_writes3, arraysize(data_writes3)); |
| 4325 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4326 | |
| 4327 | std::unique_ptr<HttpNetworkTransaction> trans( |
| 4328 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4329 | |
| 4330 | TestCompletionCallback callback; |
| 4331 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4332 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4333 | |
| 4334 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4335 | ASSERT_TRUE(response); |
| 4336 | ASSERT_TRUE(response->headers); |
| 4337 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4338 | |
| 4339 | // The following three tests assert that an authentication challenge was |
| 4340 | // received and that the stack is ready to respond to the challenge using |
| 4341 | // ambient credentials. |
| 4342 | EXPECT_EQ(401, response->headers->response_code()); |
| 4343 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4344 | EXPECT_FALSE(response->auth_challenge); |
| 4345 | |
| 4346 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4347 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4348 | response = trans->GetResponseInfo(); |
| 4349 | ASSERT_TRUE(response); |
| 4350 | ASSERT_TRUE(response->headers); |
| 4351 | |
| 4352 | // The following three tests assert that an authentication challenge was |
| 4353 | // received and that the stack needs explicit credentials before it is ready |
| 4354 | // to respond to the challenge. |
| 4355 | EXPECT_EQ(401, response->headers->response_code()); |
| 4356 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4357 | EXPECT_TRUE(response->auth_challenge); |
| 4358 | |
| 4359 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4360 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4361 | response = trans->GetResponseInfo(); |
| 4362 | ASSERT_TRUE(response); |
| 4363 | ASSERT_TRUE(response->headers); |
| 4364 | EXPECT_EQ(200, response->headers->response_code()); |
| 4365 | |
| 4366 | trans.reset(); |
| 4367 | session->CloseAllConnections(); |
| 4368 | } |
| 4369 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4370 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4371 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4372 | HttpRequestInfo request1; |
| 4373 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4374 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4375 | |
| 4376 | HttpRequestInfo request2; |
| 4377 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4378 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4379 | |
| 4380 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4381 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4382 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4383 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4385 | |
| 4386 | // Since we have proxy, should try to establish tunnel. |
| 4387 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4388 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4389 | "Host: www.example.org:443\r\n" |
| 4390 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4391 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4392 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4393 | "Host: www.example.org\r\n" |
| 4394 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4395 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4396 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4397 | "Host: www.example.org\r\n" |
| 4398 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4399 | }; |
| 4400 | |
| 4401 | // The proxy responds to the connect with a 407, using a persistent |
| 4402 | // connection. |
| 4403 | MockRead data_reads1[] = { |
| 4404 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4405 | |
| 4406 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4407 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4408 | MockRead(SYNCHRONOUS, "1"), |
| 4409 | |
| 4410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4411 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4412 | MockRead(SYNCHRONOUS, "22"), |
| 4413 | }; |
| 4414 | |
| 4415 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4416 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4417 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4418 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4420 | |
| 4421 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4422 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4424 | |
| 4425 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4427 | |
| 4428 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4429 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4430 | |
| 4431 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4432 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4433 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4434 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4435 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4436 | |
| 4437 | LoadTimingInfo load_timing_info1; |
| 4438 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4439 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4440 | |
| 4441 | trans1.reset(); |
| 4442 | |
| 4443 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4444 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4446 | |
| 4447 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4449 | |
| 4450 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4452 | |
| 4453 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4454 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4455 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4456 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4457 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4458 | |
| 4459 | LoadTimingInfo load_timing_info2; |
| 4460 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4461 | TestLoadTimingReused(load_timing_info2); |
| 4462 | |
| 4463 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4464 | |
| 4465 | trans2.reset(); |
| 4466 | session->CloseAllConnections(); |
| 4467 | } |
| 4468 | |
| 4469 | // 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] | 4470 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4471 | HttpRequestInfo request1; |
| 4472 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4473 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4474 | |
| 4475 | HttpRequestInfo request2; |
| 4476 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4477 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4478 | |
| 4479 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4480 | session_deps_.proxy_service = |
| 4481 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4482 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4483 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4485 | |
| 4486 | // Since we have proxy, should try to establish tunnel. |
| 4487 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4488 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4489 | "Host: www.example.org:443\r\n" |
| 4490 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4491 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4492 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4493 | "Host: www.example.org\r\n" |
| 4494 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4495 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4496 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4497 | "Host: www.example.org\r\n" |
| 4498 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4499 | }; |
| 4500 | |
| 4501 | // The proxy responds to the connect with a 407, using a persistent |
| 4502 | // connection. |
| 4503 | MockRead data_reads1[] = { |
| 4504 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4505 | |
| 4506 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4507 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4508 | MockRead(SYNCHRONOUS, "1"), |
| 4509 | |
| 4510 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4511 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4512 | MockRead(SYNCHRONOUS, "22"), |
| 4513 | }; |
| 4514 | |
| 4515 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4516 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4517 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4518 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4520 | |
| 4521 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4522 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4523 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4524 | |
| 4525 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | |
| 4528 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4529 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4530 | |
| 4531 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4532 | ASSERT_TRUE(response1); |
| 4533 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4534 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4535 | |
| 4536 | LoadTimingInfo load_timing_info1; |
| 4537 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4538 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4539 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4540 | |
| 4541 | trans1.reset(); |
| 4542 | |
| 4543 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4544 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4545 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4546 | |
| 4547 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4549 | |
| 4550 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4551 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4552 | |
| 4553 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4554 | ASSERT_TRUE(response2); |
| 4555 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4556 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4557 | |
| 4558 | LoadTimingInfo load_timing_info2; |
| 4559 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4560 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4561 | |
| 4562 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4563 | |
| 4564 | trans2.reset(); |
| 4565 | session->CloseAllConnections(); |
| 4566 | } |
| 4567 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4568 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4569 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4570 | HttpRequestInfo request; |
| 4571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4572 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4573 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4574 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4575 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4576 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4577 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4579 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4580 | // Since we have proxy, should use full url |
| 4581 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4582 | MockWrite( |
| 4583 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4584 | "Host: www.example.org\r\n" |
| 4585 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4586 | }; |
| 4587 | |
| 4588 | MockRead data_reads1[] = { |
| 4589 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4590 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4591 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4592 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4593 | }; |
| 4594 | |
| 4595 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4596 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4597 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4598 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4601 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4604 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4605 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4606 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4607 | |
| 4608 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4609 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4610 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4611 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4612 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4613 | TestLoadTimingNotReused(load_timing_info, |
| 4614 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4615 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4616 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4617 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4618 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4619 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4620 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4621 | EXPECT_EQ(200, response->headers->response_code()); |
| 4622 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4623 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4624 | |
| 4625 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4626 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4627 | } |
| 4628 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4629 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4630 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4631 | HttpRequestInfo request; |
| 4632 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4633 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4634 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4635 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4636 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4637 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4638 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4640 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4641 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4642 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4643 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4644 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4645 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4646 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4647 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4648 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4649 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4650 | }; |
| 4651 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4652 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4653 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4654 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4655 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4656 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4657 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4660 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4663 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4664 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4666 | |
| 4667 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4669 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4670 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4671 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4672 | TestLoadTimingNotReused(load_timing_info, |
| 4673 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4676 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4677 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4678 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4679 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4680 | |
| 4681 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4682 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4683 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4684 | } |
| 4685 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4686 | // Verifies that a session which races and wins against the owning transaction |
| 4687 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4688 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4689 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4690 | HttpRequestInfo request; |
| 4691 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4692 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4693 | |
| 4694 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4695 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4696 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4697 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4699 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4700 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4701 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4702 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4703 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4704 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4705 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4706 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4707 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4708 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4709 | }; |
| 4710 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4711 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4712 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4713 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4714 | |
| 4715 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4716 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4718 | |
| 4719 | TestCompletionCallback callback1; |
| 4720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4722 | |
| 4723 | // Stall the hostname resolution begun by the transaction. |
| 4724 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4725 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4727 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4729 | |
| 4730 | // Race a session to the proxy, which completes first. |
| 4731 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4732 | SpdySessionKey key( |
| 4733 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4734 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4735 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4736 | |
| 4737 | // Unstall the resolution begun by the transaction. |
| 4738 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4739 | session_deps_.host_resolver->ResolveAllPending(); |
| 4740 | |
| 4741 | EXPECT_FALSE(callback1.have_result()); |
| 4742 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4746 | ASSERT_TRUE(response); |
| 4747 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4748 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4749 | |
| 4750 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4751 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4752 | EXPECT_EQ(kUploadData, response_data); |
| 4753 | } |
| 4754 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4755 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4756 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4757 | HttpRequestInfo request; |
| 4758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4759 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4760 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4761 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4762 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4763 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4764 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4766 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4767 | // The first request will be a bare GET, the second request will be a |
| 4768 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4769 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4770 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4771 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4772 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4773 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4774 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4775 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4776 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4777 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4778 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4779 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4780 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4781 | }; |
| 4782 | |
| 4783 | // The first response is a 407 proxy authentication challenge, and the second |
| 4784 | // response will be a 200 response since the second request includes a valid |
| 4785 | // Authorization header. |
| 4786 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4787 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4788 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4789 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4790 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4791 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4792 | SpdySerializedFrame body_authentication( |
| 4793 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4794 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4795 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4796 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4797 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4798 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4799 | CreateMockRead(resp_data, 4), |
| 4800 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4801 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4802 | }; |
| 4803 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4804 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4805 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4807 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4808 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4809 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4812 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4816 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4818 | |
| 4819 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4820 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4822 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4823 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4824 | ASSERT_TRUE(response); |
| 4825 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4826 | EXPECT_EQ(407, response->headers->response_code()); |
| 4827 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4828 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4830 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4832 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4834 | |
| 4835 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4838 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4839 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4840 | ASSERT_TRUE(response_restart); |
| 4841 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4842 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4843 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4844 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4845 | } |
| 4846 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4847 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4848 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4849 | HttpRequestInfo request; |
| 4850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4851 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4852 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4853 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4854 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4855 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4856 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4858 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4860 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4861 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4862 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4863 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4864 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4865 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4866 | const char get[] = |
| 4867 | "GET / HTTP/1.1\r\n" |
| 4868 | "Host: www.example.org\r\n" |
| 4869 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4870 | SpdySerializedFrame wrapped_get( |
| 4871 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4872 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4873 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4874 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4875 | SpdySerializedFrame wrapped_get_resp( |
| 4876 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4877 | SpdySerializedFrame wrapped_body( |
| 4878 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4879 | SpdySerializedFrame window_update( |
| 4880 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4881 | |
| 4882 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4883 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4884 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4885 | }; |
| 4886 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4887 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4888 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4889 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4890 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4891 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4892 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4893 | }; |
| 4894 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4895 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4896 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4897 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4898 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4899 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4900 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4902 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4905 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4907 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4909 | |
| 4910 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4911 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4912 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4913 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4914 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4915 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4917 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4918 | ASSERT_TRUE(response); |
| 4919 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4920 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4921 | |
| 4922 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4923 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4924 | EXPECT_EQ("1234567890", response_data); |
| 4925 | } |
| 4926 | |
| 4927 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4928 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4929 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4930 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4931 | HttpRequestInfo request; |
| 4932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4933 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4934 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4935 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4936 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4937 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4938 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4942 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4943 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4944 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4945 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4946 | // fetch https://www.example.org/ via SPDY |
| 4947 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4948 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4949 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4950 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4951 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4952 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4953 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4954 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4955 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4956 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4957 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4958 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4959 | SpdySerializedFrame window_update_get_resp( |
| 4960 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4961 | SpdySerializedFrame window_update_body( |
| 4962 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4963 | |
| 4964 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4965 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4966 | CreateMockWrite(window_update_get_resp, 6), |
| 4967 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4968 | }; |
| 4969 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4970 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4971 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4972 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4973 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4974 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4975 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4976 | }; |
| 4977 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4978 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4979 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4980 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4981 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4982 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4983 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4985 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4986 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4987 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4989 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4991 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4993 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4994 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4995 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4996 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4997 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4998 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4999 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5000 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5001 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5002 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5003 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5005 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5006 | ASSERT_TRUE(response); |
| 5007 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5008 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5009 | |
| 5010 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5011 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5012 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5016 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5017 | HttpRequestInfo request; |
| 5018 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5019 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5020 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5021 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5022 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5023 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5024 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5025 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5027 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5028 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5029 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5030 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5031 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5032 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5033 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | |
| 5035 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5036 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5037 | }; |
| 5038 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5039 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5040 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5041 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5042 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5043 | }; |
| 5044 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5045 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5046 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5047 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5048 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5049 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5050 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5052 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5053 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5056 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5058 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5060 | |
| 5061 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5062 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5063 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5064 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5065 | } |
| 5066 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5067 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5068 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5069 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5070 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5071 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5072 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5073 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5074 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5075 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5076 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5077 | |
| 5078 | HttpRequestInfo request1; |
| 5079 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5080 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5081 | request1.load_flags = 0; |
| 5082 | |
| 5083 | HttpRequestInfo request2; |
| 5084 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5085 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5086 | request2.load_flags = 0; |
| 5087 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5088 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5089 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5090 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5091 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5092 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5093 | // Fetch https://www.example.org/ via HTTP. |
| 5094 | const char get1[] = |
| 5095 | "GET / HTTP/1.1\r\n" |
| 5096 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5097 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5098 | SpdySerializedFrame wrapped_get1( |
| 5099 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5100 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5101 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5102 | SpdySerializedFrame wrapped_get_resp1( |
| 5103 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5104 | SpdySerializedFrame wrapped_body1( |
| 5105 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5106 | SpdySerializedFrame window_update( |
| 5107 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5108 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5109 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5110 | SpdyHeaderBlock connect2_block; |
| 5111 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5112 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5113 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5114 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5115 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5116 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5117 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5118 | // Fetch https://mail.example.org/ via HTTP. |
| 5119 | const char get2[] = |
| 5120 | "GET / HTTP/1.1\r\n" |
| 5121 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5122 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5123 | SpdySerializedFrame wrapped_get2( |
| 5124 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5125 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5126 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5127 | SpdySerializedFrame wrapped_get_resp2( |
| 5128 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5129 | SpdySerializedFrame wrapped_body2( |
| 5130 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5131 | |
| 5132 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5133 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5134 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5135 | }; |
| 5136 | |
| 5137 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5138 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5139 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5140 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5141 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5142 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5143 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5144 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5145 | }; |
| 5146 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5147 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5148 | arraysize(spdy_writes)); |
| 5149 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5150 | |
| 5151 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5152 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5153 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5154 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5156 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5157 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5158 | |
| 5159 | TestCompletionCallback callback; |
| 5160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5162 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5163 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5164 | |
| 5165 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5166 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5167 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5169 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5170 | ASSERT_TRUE(response); |
| 5171 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5172 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5173 | |
| 5174 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5175 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5176 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5177 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5179 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5180 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5181 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5182 | |
| 5183 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5184 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5185 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5186 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5187 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5188 | |
| 5189 | // The requests should have different IDs, since they each are using their own |
| 5190 | // separate stream. |
| 5191 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5193 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5194 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5198 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5199 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5200 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5201 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5202 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5203 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5204 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5205 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5206 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5207 | |
| 5208 | HttpRequestInfo request1; |
| 5209 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5210 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5211 | request1.load_flags = 0; |
| 5212 | |
| 5213 | HttpRequestInfo request2; |
| 5214 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5215 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5216 | request2.load_flags = 0; |
| 5217 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5218 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5219 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5220 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5221 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5222 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5223 | // Fetch https://www.example.org/ via HTTP. |
| 5224 | const char get1[] = |
| 5225 | "GET / HTTP/1.1\r\n" |
| 5226 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5227 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5228 | SpdySerializedFrame wrapped_get1( |
| 5229 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5230 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5231 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5232 | SpdySerializedFrame wrapped_get_resp1( |
| 5233 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5234 | SpdySerializedFrame wrapped_body1( |
| 5235 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5236 | SpdySerializedFrame window_update( |
| 5237 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5238 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5239 | // Fetch https://www.example.org/2 via HTTP. |
| 5240 | const char get2[] = |
| 5241 | "GET /2 HTTP/1.1\r\n" |
| 5242 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5243 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5244 | SpdySerializedFrame wrapped_get2( |
| 5245 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5246 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5247 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5248 | SpdySerializedFrame wrapped_get_resp2( |
| 5249 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5250 | SpdySerializedFrame wrapped_body2( |
| 5251 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5252 | |
| 5253 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5254 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5255 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5256 | }; |
| 5257 | |
| 5258 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5259 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5260 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5261 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5262 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5263 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5264 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5265 | }; |
| 5266 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5267 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5268 | arraysize(spdy_writes)); |
| 5269 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5270 | |
| 5271 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5272 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5274 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5276 | |
| 5277 | TestCompletionCallback callback; |
| 5278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5279 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5281 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5283 | |
| 5284 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5286 | |
| 5287 | LoadTimingInfo load_timing_info; |
| 5288 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5289 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5290 | |
| 5291 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5292 | ASSERT_TRUE(response); |
| 5293 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5294 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5295 | |
| 5296 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5297 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5298 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5299 | trans.reset(); |
| 5300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5301 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5302 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5303 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5305 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5308 | |
| 5309 | LoadTimingInfo load_timing_info2; |
| 5310 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5311 | TestLoadTimingReused(load_timing_info2); |
| 5312 | |
| 5313 | // The requests should have the same ID. |
| 5314 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5315 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5316 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5320 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5321 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5322 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5323 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5324 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5325 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5326 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5327 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5328 | |
| 5329 | HttpRequestInfo request1; |
| 5330 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5331 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5332 | request1.load_flags = 0; |
| 5333 | |
| 5334 | HttpRequestInfo request2; |
| 5335 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5336 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5337 | request2.load_flags = 0; |
| 5338 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5339 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5340 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5341 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5342 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5343 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5344 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5345 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5346 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5347 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5348 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5349 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5350 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5352 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5353 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5354 | SpdySerializedFrame body2( |
| 5355 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5356 | |
| 5357 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5358 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5359 | }; |
| 5360 | |
| 5361 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5362 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5363 | CreateMockRead(body1, 2, ASYNC), |
| 5364 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5365 | CreateMockRead(body2, 5, ASYNC), |
| 5366 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5367 | }; |
| 5368 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5369 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5370 | arraysize(spdy_writes)); |
| 5371 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5372 | |
| 5373 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5374 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5376 | |
| 5377 | TestCompletionCallback callback; |
| 5378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5379 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5380 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5381 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5382 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5383 | |
| 5384 | LoadTimingInfo load_timing_info; |
| 5385 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5386 | TestLoadTimingNotReused(load_timing_info, |
| 5387 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5388 | |
| 5389 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5390 | ASSERT_TRUE(response); |
| 5391 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5392 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5393 | |
| 5394 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5395 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5396 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5397 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5398 | // Delete the first request, so the second one can reuse the socket. |
| 5399 | trans.reset(); |
| 5400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5401 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5402 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5403 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5404 | |
| 5405 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5406 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5407 | TestLoadTimingReused(load_timing_info2); |
| 5408 | |
| 5409 | // The requests should have the same ID. |
| 5410 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5412 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5413 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5414 | } |
| 5415 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5416 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5417 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | HttpRequestInfo request; |
| 5419 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5420 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5421 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5422 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5423 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5424 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5425 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5426 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5427 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5429 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5430 | // Since we have proxy, should use full url |
| 5431 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5432 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5433 | "Host: www.example.org\r\n" |
| 5434 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5436 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5437 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5438 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5439 | "Host: www.example.org\r\n" |
| 5440 | "Proxy-Connection: keep-alive\r\n" |
| 5441 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5442 | }; |
| 5443 | |
| 5444 | // The proxy responds to the GET with a 407, using a persistent |
| 5445 | // connection. |
| 5446 | MockRead data_reads1[] = { |
| 5447 | // No credentials. |
| 5448 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5449 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5450 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5451 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5452 | |
| 5453 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5454 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5455 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5457 | }; |
| 5458 | |
| 5459 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5460 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5461 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5462 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5465 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5471 | |
| 5472 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5474 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5475 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5476 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5477 | TestLoadTimingNotReused(load_timing_info, |
| 5478 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5480 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5481 | ASSERT_TRUE(response); |
| 5482 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5483 | EXPECT_EQ(407, response->headers->response_code()); |
| 5484 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5485 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5486 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5487 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5488 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5489 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5491 | |
| 5492 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5493 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5494 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5495 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5496 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5497 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5498 | TestLoadTimingReused(load_timing_info); |
| 5499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5500 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5501 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5502 | |
| 5503 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5504 | EXPECT_EQ(200, response->headers->response_code()); |
| 5505 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5506 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5507 | |
| 5508 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5509 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5510 | } |
| 5511 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5512 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5513 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5514 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5515 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5516 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5517 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5518 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5519 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5521 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5522 | // Since we have proxy, should try to establish tunnel. |
| 5523 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5524 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5525 | "Host: www.example.org:443\r\n" |
| 5526 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5527 | }; |
| 5528 | |
| 5529 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5530 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5531 | // No response body because the test stops reading here. |
| 5532 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5533 | }; |
| 5534 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5535 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5536 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5539 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5545 | |
| 5546 | rv = callback.WaitForResult(); |
| 5547 | EXPECT_EQ(expected_status, rv); |
| 5548 | } |
| 5549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5550 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5551 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5552 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5553 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5554 | } |
| 5555 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5556 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5557 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5558 | } |
| 5559 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5560 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5561 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5562 | } |
| 5563 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5564 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5565 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5566 | } |
| 5567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5568 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5569 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5570 | } |
| 5571 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5572 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5573 | ConnectStatusHelper( |
| 5574 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5575 | } |
| 5576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5577 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5578 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5579 | } |
| 5580 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5581 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5582 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5583 | } |
| 5584 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5585 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5586 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5587 | } |
| 5588 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5589 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5590 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5591 | } |
| 5592 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5593 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5594 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5595 | } |
| 5596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5597 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5598 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5599 | } |
| 5600 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5601 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5602 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5603 | } |
| 5604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5605 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5606 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5607 | } |
| 5608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5609 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5610 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5611 | } |
| 5612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5613 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5614 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5615 | } |
| 5616 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5617 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5618 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5619 | } |
| 5620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5621 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5622 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5623 | } |
| 5624 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5625 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5626 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5627 | } |
| 5628 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5629 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5630 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5631 | } |
| 5632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5633 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5634 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5635 | } |
| 5636 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5637 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5638 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5639 | } |
| 5640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5641 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5642 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5643 | } |
| 5644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5645 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5646 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5647 | } |
| 5648 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5649 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5650 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5651 | } |
| 5652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5653 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5654 | ConnectStatusHelperWithExpectedStatus( |
| 5655 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5656 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | } |
| 5658 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5659 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5660 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5661 | } |
| 5662 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5663 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5664 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5665 | } |
| 5666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5667 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5668 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5669 | } |
| 5670 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5671 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5672 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5673 | } |
| 5674 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5675 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5676 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5677 | } |
| 5678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5679 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5680 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5681 | } |
| 5682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5683 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5684 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5685 | } |
| 5686 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5687 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5688 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5689 | } |
| 5690 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5691 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5692 | ConnectStatusHelper( |
| 5693 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5694 | } |
| 5695 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5696 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5697 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5698 | } |
| 5699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5700 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5701 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5702 | } |
| 5703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5704 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5705 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5706 | } |
| 5707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5708 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5709 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5710 | } |
| 5711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5712 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5713 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5714 | } |
| 5715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5716 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5717 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5718 | } |
| 5719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5720 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5721 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5722 | } |
| 5723 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5724 | // Test the flow when both the proxy server AND origin server require |
| 5725 | // authentication. Again, this uses basic auth for both since that is |
| 5726 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5727 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5728 | HttpRequestInfo request; |
| 5729 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5730 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5731 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5732 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5733 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5737 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5738 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5739 | MockWrite( |
| 5740 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5741 | "Host: www.example.org\r\n" |
| 5742 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5743 | }; |
| 5744 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5745 | MockRead data_reads1[] = { |
| 5746 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5747 | // Give a couple authenticate options (only the middle one is actually |
| 5748 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5749 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5750 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5751 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5753 | // Large content-length -- won't matter, as connection will be reset. |
| 5754 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5755 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5756 | }; |
| 5757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5758 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5759 | // request we should be issuing -- the final header line contains the |
| 5760 | // proxy's credentials. |
| 5761 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5762 | MockWrite( |
| 5763 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5764 | "Host: www.example.org\r\n" |
| 5765 | "Proxy-Connection: keep-alive\r\n" |
| 5766 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5767 | }; |
| 5768 | |
| 5769 | // Now the proxy server lets the request pass through to origin server. |
| 5770 | // The origin server responds with a 401. |
| 5771 | MockRead data_reads2[] = { |
| 5772 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5773 | // Note: We are using the same realm-name as the proxy server. This is |
| 5774 | // completely valid, as realms are unique across hosts. |
| 5775 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5776 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5777 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5778 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5779 | }; |
| 5780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5781 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5782 | // the credentials for both the proxy and origin server. |
| 5783 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5784 | MockWrite( |
| 5785 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5786 | "Host: www.example.org\r\n" |
| 5787 | "Proxy-Connection: keep-alive\r\n" |
| 5788 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5789 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5790 | }; |
| 5791 | |
| 5792 | // Lastly we get the desired content. |
| 5793 | MockRead data_reads3[] = { |
| 5794 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5795 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5796 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5798 | }; |
| 5799 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5800 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5801 | data_writes1, arraysize(data_writes1)); |
| 5802 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5803 | data_writes2, arraysize(data_writes2)); |
| 5804 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5805 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5808 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5810 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5812 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5814 | |
| 5815 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5818 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5819 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5820 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5822 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5824 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5826 | |
| 5827 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5831 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5832 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5834 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5837 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5839 | |
| 5840 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5841 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5843 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5844 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5845 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5846 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5847 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5848 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5849 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5850 | // authorization headers. |
| 5851 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5852 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5853 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5854 | // bytes in the debugger. |
| 5855 | |
| 5856 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5857 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5858 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5859 | request.method = "GET"; |
| 5860 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5861 | |
| 5862 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5863 | // to other auth schemes. |
| 5864 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5865 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5866 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5867 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5869 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5870 | MockWrite data_writes1[] = { |
| 5871 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5872 | "Host: 172.22.68.17\r\n" |
| 5873 | "Connection: keep-alive\r\n\r\n"), |
| 5874 | }; |
| 5875 | |
| 5876 | MockRead data_reads1[] = { |
| 5877 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5878 | // Negotiate and NTLM are often requested together. However, we only want |
| 5879 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5880 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5881 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5882 | MockRead("Connection: close\r\n"), |
| 5883 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5884 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5885 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5886 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5887 | }; |
| 5888 | |
| 5889 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5890 | // After restarting with a null identity, this is the |
| 5891 | // request we should be issuing -- the final header line contains a Type |
| 5892 | // 1 message. |
| 5893 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5894 | "Host: 172.22.68.17\r\n" |
| 5895 | "Connection: keep-alive\r\n" |
| 5896 | "Authorization: NTLM " |
| 5897 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5899 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5900 | // (the credentials for the origin server). The second request continues |
| 5901 | // on the same connection. |
| 5902 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5903 | "Host: 172.22.68.17\r\n" |
| 5904 | "Connection: keep-alive\r\n" |
| 5905 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5906 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5907 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5908 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5909 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5910 | }; |
| 5911 | |
| 5912 | MockRead data_reads2[] = { |
| 5913 | // The origin server responds with a Type 2 message. |
| 5914 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5915 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5916 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5917 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5918 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5919 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5920 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5921 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5922 | "BtAAAAAAA=\r\n"), |
| 5923 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5924 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5925 | MockRead("You are not authorized to view this page\r\n"), |
| 5926 | |
| 5927 | // Lastly we get the desired content. |
| 5928 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5929 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5930 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5931 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5932 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5933 | }; |
| 5934 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5935 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5936 | data_writes1, arraysize(data_writes1)); |
| 5937 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5938 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5939 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5940 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5942 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5945 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5946 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5947 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5948 | |
| 5949 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5950 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5952 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5954 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5955 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5956 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5958 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5960 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5961 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5963 | |
| 5964 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5965 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5967 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5969 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5970 | ASSERT_TRUE(response); |
| 5971 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5973 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5975 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5977 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5978 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5979 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5981 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5982 | ASSERT_TRUE(response); |
| 5983 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5984 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5985 | } |
| 5986 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5987 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5988 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5989 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5990 | request.method = "GET"; |
| 5991 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5992 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5993 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5994 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5996 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5997 | MockWrite data_writes1[] = { |
| 5998 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5999 | "Host: 172.22.68.17\r\n" |
| 6000 | "Connection: keep-alive\r\n\r\n"), |
| 6001 | }; |
| 6002 | |
| 6003 | MockRead data_reads1[] = { |
| 6004 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6005 | // Negotiate and NTLM are often requested together. However, we only want |
| 6006 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6007 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6008 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6009 | MockRead("Connection: close\r\n"), |
| 6010 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6011 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6012 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6013 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6014 | }; |
| 6015 | |
| 6016 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6017 | // After restarting with a null identity, this is the |
| 6018 | // request we should be issuing -- the final header line contains a Type |
| 6019 | // 1 message. |
| 6020 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6021 | "Host: 172.22.68.17\r\n" |
| 6022 | "Connection: keep-alive\r\n" |
| 6023 | "Authorization: NTLM " |
| 6024 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6026 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6027 | // (the credentials for the origin server). The second request continues |
| 6028 | // on the same connection. |
| 6029 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6030 | "Host: 172.22.68.17\r\n" |
| 6031 | "Connection: keep-alive\r\n" |
| 6032 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6033 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6034 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6035 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6036 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6037 | }; |
| 6038 | |
| 6039 | MockRead data_reads2[] = { |
| 6040 | // The origin server responds with a Type 2 message. |
| 6041 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6042 | MockRead("WWW-Authenticate: NTLM " |
| 6043 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6044 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6045 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6046 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6047 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6048 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6049 | "BtAAAAAAA=\r\n"), |
| 6050 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6051 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6052 | MockRead("You are not authorized to view this page\r\n"), |
| 6053 | |
| 6054 | // Wrong password. |
| 6055 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6056 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6057 | MockRead("Connection: close\r\n"), |
| 6058 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6059 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6060 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6061 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6062 | }; |
| 6063 | |
| 6064 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6065 | // After restarting with a null identity, this is the |
| 6066 | // request we should be issuing -- the final header line contains a Type |
| 6067 | // 1 message. |
| 6068 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6069 | "Host: 172.22.68.17\r\n" |
| 6070 | "Connection: keep-alive\r\n" |
| 6071 | "Authorization: NTLM " |
| 6072 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6074 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6075 | // (the credentials for the origin server). The second request continues |
| 6076 | // on the same connection. |
| 6077 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6078 | "Host: 172.22.68.17\r\n" |
| 6079 | "Connection: keep-alive\r\n" |
| 6080 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6081 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6082 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6083 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6084 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6085 | }; |
| 6086 | |
| 6087 | MockRead data_reads3[] = { |
| 6088 | // The origin server responds with a Type 2 message. |
| 6089 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6090 | MockRead("WWW-Authenticate: NTLM " |
| 6091 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6092 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6093 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6094 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6095 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6096 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6097 | "BtAAAAAAA=\r\n"), |
| 6098 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6099 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6100 | MockRead("You are not authorized to view this page\r\n"), |
| 6101 | |
| 6102 | // Lastly we get the desired content. |
| 6103 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6104 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6105 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6106 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6107 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6108 | }; |
| 6109 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6110 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6111 | data_writes1, arraysize(data_writes1)); |
| 6112 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6113 | data_writes2, arraysize(data_writes2)); |
| 6114 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6115 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6117 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6118 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6120 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6122 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6123 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6124 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6125 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6126 | |
| 6127 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6128 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6130 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6132 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6133 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6134 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6136 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6137 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6138 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6140 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6142 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6143 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6147 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6148 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6150 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6151 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6152 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6155 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6156 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6158 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6159 | |
| 6160 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6162 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6164 | |
| 6165 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6168 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6170 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6171 | |
| 6172 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6173 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6175 | |
| 6176 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6177 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6179 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6180 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6181 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6182 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6183 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6184 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6185 | // Test reading a server response which has only headers, and no body. |
| 6186 | // After some maximum number of bytes is consumed, the transaction should |
| 6187 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6188 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6189 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6191 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6194 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6195 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6196 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6197 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6198 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6199 | |
| 6200 | MockRead data_reads[] = { |
| 6201 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6202 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6203 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6205 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6206 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6207 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6209 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6210 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6211 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6213 | |
| 6214 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6215 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6216 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6217 | |
| 6218 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6219 | // establish tunnel. |
| 6220 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6221 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6222 | HttpRequestInfo request; |
| 6223 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6224 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6225 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6226 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6227 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6228 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6231 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6233 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6234 | // Since we have proxy, should try to establish tunnel. |
| 6235 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6236 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6237 | "Host: www.example.org:443\r\n" |
| 6238 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6239 | }; |
| 6240 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6241 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6242 | // connection. Usually a proxy would return 501 (not implemented), |
| 6243 | // or 200 (tunnel established). |
| 6244 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6245 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6246 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6247 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6248 | }; |
| 6249 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6250 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6251 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6252 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6254 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6256 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6258 | |
| 6259 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6260 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6261 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6262 | // Empty the current queue. This is necessary because idle sockets are |
| 6263 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6264 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6265 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6266 | // We now check to make sure the TCPClientSocket was not added back to |
| 6267 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6268 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6269 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6270 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6271 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6272 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6273 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6274 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6275 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6276 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6277 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6278 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6279 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6280 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6284 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6285 | MockRead data_reads[] = { |
| 6286 | // A part of the response body is received with the response headers. |
| 6287 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6288 | // The rest of the response body is received in two parts. |
| 6289 | MockRead("lo"), |
| 6290 | MockRead(" world"), |
| 6291 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6292 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6293 | }; |
| 6294 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6295 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6296 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6298 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6299 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6300 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6302 | |
| 6303 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6306 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6307 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6308 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6309 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6310 | std::string status_line = response->headers->GetStatusLine(); |
| 6311 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6312 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6313 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6314 | |
| 6315 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6316 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6318 | EXPECT_EQ("hello world", response_data); |
| 6319 | |
| 6320 | // Empty the current queue. This is necessary because idle sockets are |
| 6321 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6322 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6323 | |
| 6324 | // 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] | 6325 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6326 | } |
| 6327 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6328 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6329 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6330 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6331 | HttpRequestInfo request; |
| 6332 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6333 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6334 | |
| 6335 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6336 | MockWrite( |
| 6337 | "GET / HTTP/1.1\r\n" |
| 6338 | "Host: www.example.org\r\n" |
| 6339 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6340 | }; |
| 6341 | |
| 6342 | MockRead data_reads[] = { |
| 6343 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6344 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6345 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6346 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6347 | }; |
| 6348 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6349 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6351 | |
| 6352 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6353 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6356 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6358 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6359 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6361 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6362 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6364 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6366 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6367 | ASSERT_TRUE(response); |
| 6368 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6369 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6370 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6371 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6372 | |
| 6373 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6374 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6376 | EXPECT_EQ("hello world", response_data); |
| 6377 | |
| 6378 | // Empty the current queue. This is necessary because idle sockets are |
| 6379 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6380 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6381 | |
| 6382 | // 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] | 6383 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6387 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6388 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6389 | HttpRequestInfo request; |
| 6390 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6391 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6392 | |
| 6393 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6394 | MockWrite( |
| 6395 | "GET / HTTP/1.1\r\n" |
| 6396 | "Host: www.example.org\r\n" |
| 6397 | "Connection: keep-alive\r\n\r\n"), |
| 6398 | MockWrite( |
| 6399 | "GET / HTTP/1.1\r\n" |
| 6400 | "Host: www.example.org\r\n" |
| 6401 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6402 | }; |
| 6403 | |
| 6404 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6405 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6406 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6407 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6408 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6409 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6411 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6412 | |
| 6413 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6414 | data_writes, arraysize(data_writes)); |
| 6415 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6416 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6417 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6418 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6419 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6420 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6421 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6423 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6426 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6428 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6429 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6430 | |
| 6431 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6432 | ASSERT_TRUE(response); |
| 6433 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6434 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6435 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6436 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6437 | |
| 6438 | std::string response_data; |
| 6439 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6441 | EXPECT_EQ("hello world", response_data); |
| 6442 | |
| 6443 | // Empty the current queue. This is necessary because idle sockets are |
| 6444 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6445 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6446 | |
| 6447 | // 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] | 6448 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6449 | |
| 6450 | // Now start the second transaction, which should reuse the previous socket. |
| 6451 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6452 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6453 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6454 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6455 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6457 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6458 | |
| 6459 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6460 | ASSERT_TRUE(response); |
| 6461 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6462 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6463 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6464 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6465 | |
| 6466 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6468 | EXPECT_EQ("hello world", response_data); |
| 6469 | |
| 6470 | // Empty the current queue. This is necessary because idle sockets are |
| 6471 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6472 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6473 | |
| 6474 | // 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] | 6475 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6476 | } |
| 6477 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6478 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6479 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6480 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6481 | HttpRequestInfo request; |
| 6482 | request.method = "GET"; |
| 6483 | request.url = GURL("http://www.example.org/"); |
| 6484 | request.load_flags = 0; |
| 6485 | |
| 6486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6489 | |
| 6490 | MockRead data_reads[] = { |
| 6491 | // A part of the response body is received with the response headers. |
| 6492 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6493 | // The rest of the response body is received in two parts. |
| 6494 | MockRead("lo"), MockRead(" world"), |
| 6495 | MockRead("junk"), // Should not be read!! |
| 6496 | MockRead(SYNCHRONOUS, OK), |
| 6497 | }; |
| 6498 | |
| 6499 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6501 | |
| 6502 | TestCompletionCallback callback; |
| 6503 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6504 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6506 | |
| 6507 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6509 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6510 | ASSERT_TRUE(response); |
| 6511 | EXPECT_TRUE(response->headers); |
| 6512 | std::string status_line = response->headers->GetStatusLine(); |
| 6513 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6514 | |
| 6515 | // Make memory critical notification and ensure the transaction still has been |
| 6516 | // operating right. |
| 6517 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6518 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6519 | base::RunLoop().RunUntilIdle(); |
| 6520 | |
| 6521 | // Socket should not be flushed as long as it is not idle. |
| 6522 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6523 | |
| 6524 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6525 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6526 | EXPECT_THAT(rv, IsOk()); |
| 6527 | EXPECT_EQ("hello world", response_data); |
| 6528 | |
| 6529 | // Empty the current queue. This is necessary because idle sockets are |
| 6530 | // added to the connection pool asynchronously with a PostTask. |
| 6531 | base::RunLoop().RunUntilIdle(); |
| 6532 | |
| 6533 | // We now check to make sure the socket was added back to the pool. |
| 6534 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6535 | |
| 6536 | // Idle sockets should be flushed now. |
| 6537 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6538 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6539 | base::RunLoop().RunUntilIdle(); |
| 6540 | |
| 6541 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6542 | } |
| 6543 | |
| 6544 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6545 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6546 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6547 | HttpRequestInfo request; |
| 6548 | request.method = "GET"; |
| 6549 | request.url = GURL("https://www.example.org/"); |
| 6550 | request.load_flags = 0; |
| 6551 | |
| 6552 | MockWrite data_writes[] = { |
| 6553 | MockWrite("GET / HTTP/1.1\r\n" |
| 6554 | "Host: www.example.org\r\n" |
| 6555 | "Connection: keep-alive\r\n\r\n"), |
| 6556 | }; |
| 6557 | |
| 6558 | MockRead data_reads[] = { |
| 6559 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6560 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6561 | |
| 6562 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6563 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6564 | |
| 6565 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6566 | arraysize(data_writes)); |
| 6567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6568 | |
| 6569 | TestCompletionCallback callback; |
| 6570 | |
| 6571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6572 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6573 | |
| 6574 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6575 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6576 | |
| 6577 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6579 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6580 | ASSERT_TRUE(response); |
| 6581 | ASSERT_TRUE(response->headers); |
| 6582 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6583 | |
| 6584 | // Make memory critical notification and ensure the transaction still has been |
| 6585 | // operating right. |
| 6586 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6587 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6588 | base::RunLoop().RunUntilIdle(); |
| 6589 | |
| 6590 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6591 | |
| 6592 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6593 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6594 | EXPECT_THAT(rv, IsOk()); |
| 6595 | EXPECT_EQ("hello world", response_data); |
| 6596 | |
| 6597 | // Empty the current queue. This is necessary because idle sockets are |
| 6598 | // added to the connection pool asynchronously with a PostTask. |
| 6599 | base::RunLoop().RunUntilIdle(); |
| 6600 | |
| 6601 | // We now check to make sure the socket was added back to the pool. |
| 6602 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6603 | |
| 6604 | // Make memory notification once again and ensure idle socket is closed. |
| 6605 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6606 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6607 | base::RunLoop().RunUntilIdle(); |
| 6608 | |
| 6609 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6610 | } |
| 6611 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6612 | // Make sure that we recycle a socket after a zero-length response. |
| 6613 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6614 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6615 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6617 | request.url = GURL( |
| 6618 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6619 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6620 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6621 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6622 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6623 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6624 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6625 | MockRead data_reads[] = { |
| 6626 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6627 | "Content-Length: 0\r\n" |
| 6628 | "Content-Type: text/html\r\n\r\n"), |
| 6629 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6630 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6631 | }; |
| 6632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6635 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6636 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6637 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6640 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6642 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6644 | |
| 6645 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6648 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6649 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6650 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6651 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6652 | std::string status_line = response->headers->GetStatusLine(); |
| 6653 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6654 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6655 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6656 | |
| 6657 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6658 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6660 | EXPECT_EQ("", response_data); |
| 6661 | |
| 6662 | // Empty the current queue. This is necessary because idle sockets are |
| 6663 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6664 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6665 | |
| 6666 | // 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] | 6667 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6668 | } |
| 6669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6670 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6671 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6672 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6673 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6674 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6675 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6676 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6677 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6678 | // after use. |
| 6679 | request[0].method = "GET"; |
| 6680 | request[0].url = GURL("http://www.google.com/"); |
| 6681 | request[0].load_flags = 0; |
| 6682 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6683 | // transaction 1. The first attempts fails when writing the POST data. |
| 6684 | // This causes the transaction to retry with a new socket. The second |
| 6685 | // attempt succeeds. |
| 6686 | request[1].method = "POST"; |
| 6687 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6688 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6689 | request[1].load_flags = 0; |
| 6690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6692 | |
| 6693 | // The first socket is used for transaction 1 and the first attempt of |
| 6694 | // transaction 2. |
| 6695 | |
| 6696 | // The response of transaction 1. |
| 6697 | MockRead data_reads1[] = { |
| 6698 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6699 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6700 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6701 | }; |
| 6702 | // The mock write results of transaction 1 and the first attempt of |
| 6703 | // transaction 2. |
| 6704 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6705 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6706 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6707 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6708 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6709 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6710 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6711 | |
| 6712 | // The second socket is used for the second attempt of transaction 2. |
| 6713 | |
| 6714 | // The response of transaction 2. |
| 6715 | MockRead data_reads2[] = { |
| 6716 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6717 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6718 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6719 | }; |
| 6720 | // The mock write results of the second attempt of transaction 2. |
| 6721 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6722 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6723 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6724 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6725 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6726 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6727 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6729 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6730 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6731 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6732 | "hello world", "welcome" |
| 6733 | }; |
| 6734 | |
| 6735 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6738 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6739 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6740 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6742 | |
| 6743 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6744 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6746 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6747 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6748 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6749 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6750 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6751 | |
| 6752 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6753 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6755 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6756 | } |
| 6757 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6758 | |
| 6759 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6760 | // 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] | 6761 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6762 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6763 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6765 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6766 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6770 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6771 | // The password contains an escaped character -- for this test to pass it |
| 6772 | // will need to be unescaped by HttpNetworkTransaction. |
| 6773 | EXPECT_EQ("b%40r", request.url.password()); |
| 6774 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6775 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6776 | MockWrite( |
| 6777 | "GET / HTTP/1.1\r\n" |
| 6778 | "Host: www.example.org\r\n" |
| 6779 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6780 | }; |
| 6781 | |
| 6782 | MockRead data_reads1[] = { |
| 6783 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6784 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6785 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6786 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6787 | }; |
| 6788 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6789 | // After the challenge above, the transaction will be restarted using the |
| 6790 | // identity from the url (foo, b@r) to answer the challenge. |
| 6791 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6792 | MockWrite( |
| 6793 | "GET / HTTP/1.1\r\n" |
| 6794 | "Host: www.example.org\r\n" |
| 6795 | "Connection: keep-alive\r\n" |
| 6796 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6797 | }; |
| 6798 | |
| 6799 | MockRead data_reads2[] = { |
| 6800 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6801 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6802 | MockRead(SYNCHRONOUS, OK), |
| 6803 | }; |
| 6804 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6805 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6806 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6807 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6808 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6810 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6812 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6813 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6815 | rv = callback1.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_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6818 | |
| 6819 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6820 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6822 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6823 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6824 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6826 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6827 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6828 | |
| 6829 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6830 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6831 | |
| 6832 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6833 | |
| 6834 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6835 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6836 | } |
| 6837 | |
| 6838 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6839 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6840 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6841 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6842 | HttpRequestInfo request; |
| 6843 | request.method = "GET"; |
| 6844 | // Note: the URL has a username:password in it. The password "baz" is |
| 6845 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6846 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6847 | |
| 6848 | request.load_flags = LOAD_NORMAL; |
| 6849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6851 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6852 | |
| 6853 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6854 | MockWrite( |
| 6855 | "GET / HTTP/1.1\r\n" |
| 6856 | "Host: www.example.org\r\n" |
| 6857 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6858 | }; |
| 6859 | |
| 6860 | MockRead data_reads1[] = { |
| 6861 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6862 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6863 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6864 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6865 | }; |
| 6866 | |
| 6867 | // After the challenge above, the transaction will be restarted using the |
| 6868 | // identity from the url (foo, baz) to answer the challenge. |
| 6869 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6870 | MockWrite( |
| 6871 | "GET / HTTP/1.1\r\n" |
| 6872 | "Host: www.example.org\r\n" |
| 6873 | "Connection: keep-alive\r\n" |
| 6874 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6875 | }; |
| 6876 | |
| 6877 | MockRead data_reads2[] = { |
| 6878 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6879 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6880 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6881 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6882 | }; |
| 6883 | |
| 6884 | // After the challenge above, the transaction will be restarted using the |
| 6885 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6886 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6887 | MockWrite( |
| 6888 | "GET / HTTP/1.1\r\n" |
| 6889 | "Host: www.example.org\r\n" |
| 6890 | "Connection: keep-alive\r\n" |
| 6891 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6892 | }; |
| 6893 | |
| 6894 | MockRead data_reads3[] = { |
| 6895 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6896 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6897 | MockRead(SYNCHRONOUS, OK), |
| 6898 | }; |
| 6899 | |
| 6900 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6901 | data_writes1, arraysize(data_writes1)); |
| 6902 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6903 | data_writes2, arraysize(data_writes2)); |
| 6904 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6905 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6906 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6907 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6908 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6909 | |
| 6910 | TestCompletionCallback callback1; |
| 6911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6912 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6914 | |
| 6915 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6916 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6918 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6919 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6920 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6922 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6923 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6924 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6926 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6927 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6928 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6929 | |
| 6930 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6931 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6933 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6934 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6935 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6937 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6938 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6939 | |
| 6940 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6941 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6942 | |
| 6943 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6944 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6945 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6946 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6947 | } |
| 6948 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6949 | |
| 6950 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6951 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6952 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6953 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6954 | HttpRequestInfo request; |
| 6955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6956 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6957 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6958 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6960 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6961 | |
| 6962 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6963 | MockWrite( |
| 6964 | "GET / HTTP/1.1\r\n" |
| 6965 | "Host: www.example.org\r\n" |
| 6966 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6967 | }; |
| 6968 | |
| 6969 | MockRead data_reads1[] = { |
| 6970 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6971 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6972 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6973 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6974 | }; |
| 6975 | |
| 6976 | // After the challenge above, the transaction will be restarted using the |
| 6977 | // identity supplied by the user, not the one in the URL, to answer the |
| 6978 | // challenge. |
| 6979 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6980 | MockWrite( |
| 6981 | "GET / HTTP/1.1\r\n" |
| 6982 | "Host: www.example.org\r\n" |
| 6983 | "Connection: keep-alive\r\n" |
| 6984 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6985 | }; |
| 6986 | |
| 6987 | MockRead data_reads3[] = { |
| 6988 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6989 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6990 | MockRead(SYNCHRONOUS, OK), |
| 6991 | }; |
| 6992 | |
| 6993 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6994 | data_writes1, arraysize(data_writes1)); |
| 6995 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6996 | data_writes3, arraysize(data_writes3)); |
| 6997 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6998 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6999 | |
| 7000 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7001 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7004 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7005 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7008 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7009 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7010 | |
| 7011 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7012 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7014 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7015 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7016 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7018 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7019 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7020 | |
| 7021 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7022 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7023 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7024 | |
| 7025 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7026 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7027 | } |
| 7028 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7029 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7030 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7032 | |
| 7033 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7034 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7035 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7037 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7039 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7040 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7041 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7042 | MockWrite( |
| 7043 | "GET /x/y/z HTTP/1.1\r\n" |
| 7044 | "Host: www.example.org\r\n" |
| 7045 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7046 | }; |
| 7047 | |
| 7048 | MockRead data_reads1[] = { |
| 7049 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7050 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7051 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7052 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7053 | }; |
| 7054 | |
| 7055 | // Resend with authorization (username=foo, password=bar) |
| 7056 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7057 | MockWrite( |
| 7058 | "GET /x/y/z HTTP/1.1\r\n" |
| 7059 | "Host: www.example.org\r\n" |
| 7060 | "Connection: keep-alive\r\n" |
| 7061 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7062 | }; |
| 7063 | |
| 7064 | // Sever accepts the authorization. |
| 7065 | MockRead data_reads2[] = { |
| 7066 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7067 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7068 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7069 | }; |
| 7070 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7071 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7072 | data_writes1, arraysize(data_writes1)); |
| 7073 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7074 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7075 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7076 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7078 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7079 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7080 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7082 | |
| 7083 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7084 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7086 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7087 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7088 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7090 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7092 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7093 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7095 | |
| 7096 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7099 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7100 | ASSERT_TRUE(response); |
| 7101 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7102 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7103 | } |
| 7104 | |
| 7105 | // ------------------------------------------------------------------------ |
| 7106 | |
| 7107 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7108 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7109 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7110 | request.method = "GET"; |
| 7111 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7112 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7113 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7116 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7117 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7118 | MockWrite( |
| 7119 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7120 | "Host: www.example.org\r\n" |
| 7121 | "Connection: keep-alive\r\n" |
| 7122 | // Send preemptive authorization for MyRealm1 |
| 7123 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7124 | }; |
| 7125 | |
| 7126 | // The server didn't like the preemptive authorization, and |
| 7127 | // challenges us for a different realm (MyRealm2). |
| 7128 | MockRead data_reads1[] = { |
| 7129 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7130 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7131 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7132 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7133 | }; |
| 7134 | |
| 7135 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7136 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7137 | MockWrite( |
| 7138 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7139 | "Host: www.example.org\r\n" |
| 7140 | "Connection: keep-alive\r\n" |
| 7141 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7142 | }; |
| 7143 | |
| 7144 | // Sever accepts the authorization. |
| 7145 | MockRead data_reads2[] = { |
| 7146 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7147 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7148 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7149 | }; |
| 7150 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7151 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7152 | data_writes1, arraysize(data_writes1)); |
| 7153 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7154 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7155 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7156 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7158 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7159 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7160 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7162 | |
| 7163 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7166 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7167 | ASSERT_TRUE(response); |
| 7168 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7169 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7170 | EXPECT_EQ("http://www.example.org", |
| 7171 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7172 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7173 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7175 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7177 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7178 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7179 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7180 | |
| 7181 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7182 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7184 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7185 | ASSERT_TRUE(response); |
| 7186 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7187 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7188 | } |
| 7189 | |
| 7190 | // ------------------------------------------------------------------------ |
| 7191 | |
| 7192 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7193 | // succeed with preemptive authorization. |
| 7194 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7195 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7196 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7197 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7199 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7200 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7201 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7202 | MockWrite( |
| 7203 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7204 | "Host: www.example.org\r\n" |
| 7205 | "Connection: keep-alive\r\n" |
| 7206 | // The authorization for MyRealm1 gets sent preemptively |
| 7207 | // (since the url is in the same protection space) |
| 7208 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7209 | }; |
| 7210 | |
| 7211 | // Sever accepts the preemptive authorization |
| 7212 | MockRead data_reads1[] = { |
| 7213 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7214 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7216 | }; |
| 7217 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7218 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7219 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7222 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7223 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7224 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7226 | |
| 7227 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7231 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7232 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7233 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7234 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7235 | } |
| 7236 | |
| 7237 | // ------------------------------------------------------------------------ |
| 7238 | |
| 7239 | // Transaction 4: request another URL in MyRealm (however the |
| 7240 | // url is not known to belong to the protection space, so no pre-auth). |
| 7241 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7242 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7243 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7244 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7246 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7247 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7248 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7249 | MockWrite( |
| 7250 | "GET /x/1 HTTP/1.1\r\n" |
| 7251 | "Host: www.example.org\r\n" |
| 7252 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7253 | }; |
| 7254 | |
| 7255 | MockRead data_reads1[] = { |
| 7256 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7257 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7258 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7259 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7260 | }; |
| 7261 | |
| 7262 | // Resend with authorization from MyRealm's cache. |
| 7263 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7264 | MockWrite( |
| 7265 | "GET /x/1 HTTP/1.1\r\n" |
| 7266 | "Host: www.example.org\r\n" |
| 7267 | "Connection: keep-alive\r\n" |
| 7268 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7269 | }; |
| 7270 | |
| 7271 | // Sever accepts the authorization. |
| 7272 | MockRead data_reads2[] = { |
| 7273 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7274 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7275 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7276 | }; |
| 7277 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7278 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7279 | data_writes1, arraysize(data_writes1)); |
| 7280 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7281 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7282 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7283 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7285 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7287 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7289 | |
| 7290 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7291 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7293 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7294 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7295 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7297 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7298 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7299 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7301 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7302 | ASSERT_TRUE(response); |
| 7303 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7304 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7305 | } |
| 7306 | |
| 7307 | // ------------------------------------------------------------------------ |
| 7308 | |
| 7309 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7310 | // cached identity. Should invalidate and re-prompt. |
| 7311 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7312 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7313 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7314 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7316 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7317 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7318 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7319 | MockWrite( |
| 7320 | "GET /p/q/t HTTP/1.1\r\n" |
| 7321 | "Host: www.example.org\r\n" |
| 7322 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7323 | }; |
| 7324 | |
| 7325 | MockRead data_reads1[] = { |
| 7326 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7327 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7328 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7329 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7330 | }; |
| 7331 | |
| 7332 | // Resend with authorization from cache for MyRealm. |
| 7333 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7334 | MockWrite( |
| 7335 | "GET /p/q/t HTTP/1.1\r\n" |
| 7336 | "Host: www.example.org\r\n" |
| 7337 | "Connection: keep-alive\r\n" |
| 7338 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | // Sever rejects the authorization. |
| 7342 | MockRead data_reads2[] = { |
| 7343 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7344 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7345 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7346 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7347 | }; |
| 7348 | |
| 7349 | // At this point we should prompt for new credentials for MyRealm. |
| 7350 | // Restart with username=foo3, password=foo4. |
| 7351 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7352 | MockWrite( |
| 7353 | "GET /p/q/t HTTP/1.1\r\n" |
| 7354 | "Host: www.example.org\r\n" |
| 7355 | "Connection: keep-alive\r\n" |
| 7356 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7357 | }; |
| 7358 | |
| 7359 | // Sever accepts the authorization. |
| 7360 | MockRead data_reads3[] = { |
| 7361 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7362 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7363 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7364 | }; |
| 7365 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7366 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7367 | data_writes1, arraysize(data_writes1)); |
| 7368 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7369 | data_writes2, arraysize(data_writes2)); |
| 7370 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7371 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7372 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7373 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7374 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7376 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7378 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7380 | |
| 7381 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7384 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7385 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7386 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7387 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7388 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7389 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7390 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7393 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7394 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7396 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7399 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7401 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7402 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7405 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7406 | ASSERT_TRUE(response); |
| 7407 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7408 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7409 | } |
| 7410 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7411 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7412 | // Tests that nonce count increments when multiple auth attempts |
| 7413 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7414 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7415 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7416 | new HttpAuthHandlerDigest::Factory(); |
| 7417 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7418 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7419 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7420 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7422 | |
| 7423 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7424 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7425 | HttpRequestInfo request; |
| 7426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7427 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7429 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7430 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7431 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7432 | MockWrite( |
| 7433 | "GET /x/y/z HTTP/1.1\r\n" |
| 7434 | "Host: www.example.org\r\n" |
| 7435 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7436 | }; |
| 7437 | |
| 7438 | MockRead data_reads1[] = { |
| 7439 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7440 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7441 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7442 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7443 | }; |
| 7444 | |
| 7445 | // Resend with authorization (username=foo, password=bar) |
| 7446 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7447 | MockWrite( |
| 7448 | "GET /x/y/z HTTP/1.1\r\n" |
| 7449 | "Host: www.example.org\r\n" |
| 7450 | "Connection: keep-alive\r\n" |
| 7451 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7452 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7453 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7454 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7455 | }; |
| 7456 | |
| 7457 | // Sever accepts the authorization. |
| 7458 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7459 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7460 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7461 | }; |
| 7462 | |
| 7463 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7464 | data_writes1, arraysize(data_writes1)); |
| 7465 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7466 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7467 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7468 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7470 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7472 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7474 | |
| 7475 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7479 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7480 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7482 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7485 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7487 | |
| 7488 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7491 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7492 | ASSERT_TRUE(response); |
| 7493 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | // ------------------------------------------------------------------------ |
| 7497 | |
| 7498 | // Transaction 2: Request another resource in digestive's protection space. |
| 7499 | // This will preemptively add an Authorization header which should have an |
| 7500 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7501 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7502 | HttpRequestInfo request; |
| 7503 | request.method = "GET"; |
| 7504 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7505 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7506 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7509 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7510 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7511 | MockWrite( |
| 7512 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7513 | "Host: www.example.org\r\n" |
| 7514 | "Connection: keep-alive\r\n" |
| 7515 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7516 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7517 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7518 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | // Sever accepts the authorization. |
| 7522 | MockRead data_reads1[] = { |
| 7523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7524 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7526 | }; |
| 7527 | |
| 7528 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7529 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7530 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7532 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7534 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7536 | |
| 7537 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7538 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7540 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7541 | ASSERT_TRUE(response); |
| 7542 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7543 | } |
| 7544 | } |
| 7545 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7546 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7547 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7548 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7550 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7551 | |
| 7552 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7553 | trans.read_buf_ = new IOBuffer(15); |
| 7554 | trans.read_buf_len_ = 15; |
| 7555 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7556 | |
| 7557 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7558 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7559 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7560 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7561 | response->response_time = base::Time::Now(); |
| 7562 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7563 | |
| 7564 | { // Setup state for response_.vary_data |
| 7565 | HttpRequestInfo request; |
| 7566 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7567 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7568 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7569 | request.extra_headers.SetHeader("Foo", "1"); |
| 7570 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7571 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7572 | } |
| 7573 | |
| 7574 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7575 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7576 | |
| 7577 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7578 | EXPECT_FALSE(trans.read_buf_); |
| 7579 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7580 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7581 | EXPECT_FALSE(response->auth_challenge); |
| 7582 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7583 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7584 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7585 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7586 | } |
| 7587 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7588 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7589 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7590 | HttpRequestInfo request; |
| 7591 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7592 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7596 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7597 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7598 | MockWrite( |
| 7599 | "GET / HTTP/1.1\r\n" |
| 7600 | "Host: www.example.org\r\n" |
| 7601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7602 | }; |
| 7603 | |
| 7604 | MockRead data_reads[] = { |
| 7605 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7606 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7607 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7608 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7609 | }; |
| 7610 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7611 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7612 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7613 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7614 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7615 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7616 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7617 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7622 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7623 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7624 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7626 | |
| 7627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7628 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7630 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7632 | |
| 7633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7634 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7636 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7637 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7638 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7639 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7640 | } |
| 7641 | |
| 7642 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7643 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7644 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7645 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7646 | |
| 7647 | HttpRequestInfo request; |
| 7648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7649 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7650 | |
| 7651 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7652 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7653 | "Host: www.example.org:443\r\n" |
| 7654 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7655 | }; |
| 7656 | |
| 7657 | MockRead proxy_reads[] = { |
| 7658 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7659 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7660 | }; |
| 7661 | |
| 7662 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7663 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7664 | "Host: www.example.org:443\r\n" |
| 7665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7666 | MockWrite("GET / HTTP/1.1\r\n" |
| 7667 | "Host: www.example.org\r\n" |
| 7668 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7669 | }; |
| 7670 | |
| 7671 | MockRead data_reads[] = { |
| 7672 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7673 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7674 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7675 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7676 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7677 | }; |
| 7678 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7679 | StaticSocketDataProvider ssl_bad_certificate( |
| 7680 | proxy_reads, arraysize(proxy_reads), |
| 7681 | proxy_writes, arraysize(proxy_writes)); |
| 7682 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7683 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7684 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7685 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7686 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7687 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7692 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7693 | |
| 7694 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7695 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7696 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7698 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7699 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7702 | |
| 7703 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7704 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7706 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7708 | |
| 7709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7712 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7713 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7714 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7715 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7716 | } |
| 7717 | } |
| 7718 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7719 | |
| 7720 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7721 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7722 | session_deps_.proxy_service = |
| 7723 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7724 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7725 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7726 | |
| 7727 | HttpRequestInfo request; |
| 7728 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7729 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7730 | |
| 7731 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7732 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7733 | "Host: www.example.org:443\r\n" |
| 7734 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7735 | MockWrite("GET / HTTP/1.1\r\n" |
| 7736 | "Host: www.example.org\r\n" |
| 7737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7738 | }; |
| 7739 | |
| 7740 | MockRead data_reads[] = { |
| 7741 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7742 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7743 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7744 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7745 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7746 | }; |
| 7747 | |
| 7748 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7749 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7750 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7751 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7752 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7753 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7757 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7762 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7764 | |
| 7765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7766 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7767 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7768 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7769 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7770 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7771 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7772 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7773 | EXPECT_EQ(200, response->headers->response_code()); |
| 7774 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7775 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7776 | |
| 7777 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7778 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7779 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7780 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7781 | } |
| 7782 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7783 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7784 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7785 | session_deps_.proxy_service = |
| 7786 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7787 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7788 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7789 | |
| 7790 | HttpRequestInfo request; |
| 7791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7792 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7793 | |
| 7794 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7795 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7796 | "Host: www.example.org:443\r\n" |
| 7797 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7798 | }; |
| 7799 | |
| 7800 | MockRead data_reads[] = { |
| 7801 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7802 | MockRead("Location: http://login.example.com/\r\n"), |
| 7803 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7805 | }; |
| 7806 | |
| 7807 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7808 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7809 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7810 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7811 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7812 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7814 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7817 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7819 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7821 | |
| 7822 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7823 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7824 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7825 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7826 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7827 | |
| 7828 | EXPECT_EQ(302, response->headers->response_code()); |
| 7829 | std::string url; |
| 7830 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7831 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7832 | |
| 7833 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7834 | // timing for the proxy connection instead of the connection to the host, |
| 7835 | // and no send / receive times. |
| 7836 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7837 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7838 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7839 | |
| 7840 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7841 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7842 | |
| 7843 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7844 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7845 | load_timing_info.proxy_resolve_end); |
| 7846 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7847 | load_timing_info.connect_timing.connect_start); |
| 7848 | ExpectConnectTimingHasTimes( |
| 7849 | load_timing_info.connect_timing, |
| 7850 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7851 | |
| 7852 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7853 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7854 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7858 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7859 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7860 | |
| 7861 | HttpRequestInfo request; |
| 7862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7863 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7864 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7865 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7866 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7867 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7868 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7869 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7870 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7871 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7872 | }; |
| 7873 | |
| 7874 | static const char* const kExtraHeaders[] = { |
| 7875 | "location", |
| 7876 | "http://login.example.com/", |
| 7877 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7878 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7879 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7880 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7881 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7882 | }; |
| 7883 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7884 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7885 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7886 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7887 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7888 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7892 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7893 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7896 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7897 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7899 | |
| 7900 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7901 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7902 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7903 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7904 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7905 | |
| 7906 | EXPECT_EQ(302, response->headers->response_code()); |
| 7907 | std::string url; |
| 7908 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7909 | EXPECT_EQ("http://login.example.com/", url); |
| 7910 | } |
| 7911 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7912 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7913 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7914 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7915 | |
| 7916 | HttpRequestInfo request; |
| 7917 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7918 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7919 | |
| 7920 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7921 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7922 | "Host: www.example.org:443\r\n" |
| 7923 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7924 | }; |
| 7925 | |
| 7926 | MockRead data_reads[] = { |
| 7927 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7928 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7929 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7931 | }; |
| 7932 | |
| 7933 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7934 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7935 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7936 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7937 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7940 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7947 | |
| 7948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7949 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7950 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7951 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7952 | } |
| 7953 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7954 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7955 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7956 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7957 | |
| 7958 | HttpRequestInfo request; |
| 7959 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7960 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7961 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7962 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7963 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7964 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7965 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7966 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7967 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7968 | }; |
| 7969 | |
| 7970 | static const char* const kExtraHeaders[] = { |
| 7971 | "location", |
| 7972 | "http://login.example.com/", |
| 7973 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7974 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7975 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7976 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7977 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7978 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7979 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7980 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7981 | }; |
| 7982 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7983 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7984 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7985 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7986 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7987 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7989 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7991 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7992 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7995 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7996 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7998 | |
| 7999 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8000 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8001 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8002 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8003 | } |
| 8004 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8005 | // Test the request-challenge-retry sequence for basic auth, through |
| 8006 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8007 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8008 | HttpRequestInfo request; |
| 8009 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8010 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8011 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8012 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8013 | |
| 8014 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8015 | session_deps_.proxy_service = |
| 8016 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8017 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8018 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8020 | |
| 8021 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8022 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8023 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8024 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8025 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8026 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8028 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8029 | // be issuing -- the final header line contains the credentials. |
| 8030 | const char* const kAuthCredentials[] = { |
| 8031 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8032 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8033 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8034 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8035 | HostPortPair("www.example.org", 443))); |
| 8036 | // fetch https://www.example.org/ via HTTP |
| 8037 | const char get[] = |
| 8038 | "GET / HTTP/1.1\r\n" |
| 8039 | "Host: www.example.org\r\n" |
| 8040 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8041 | SpdySerializedFrame wrapped_get( |
| 8042 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8043 | |
| 8044 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8045 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8046 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8047 | }; |
| 8048 | |
| 8049 | // The proxy responds to the connect with a 407, using a persistent |
| 8050 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8051 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8052 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8053 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8054 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8055 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8056 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8057 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8058 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8059 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8060 | "Content-Length: 5\r\n\r\n"; |
| 8061 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8062 | SpdySerializedFrame wrapped_get_resp( |
| 8063 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8064 | SpdySerializedFrame wrapped_body( |
| 8065 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8066 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8067 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8068 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8069 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8070 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8071 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8072 | }; |
| 8073 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8074 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8075 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8076 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8077 | // Negotiate SPDY to the proxy |
| 8078 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8079 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8081 | // Vanilla SSL to the server |
| 8082 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8084 | |
| 8085 | TestCompletionCallback callback1; |
| 8086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8087 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8088 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8089 | |
| 8090 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8092 | |
| 8093 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8094 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8095 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8096 | log.GetEntries(&entries); |
| 8097 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8098 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8099 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8100 | ExpectLogContainsSomewhere( |
| 8101 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8102 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8103 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8104 | |
| 8105 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8106 | ASSERT_TRUE(response); |
| 8107 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8108 | EXPECT_EQ(407, response->headers->response_code()); |
| 8109 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8110 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8111 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8112 | |
| 8113 | TestCompletionCallback callback2; |
| 8114 | |
| 8115 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8116 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8118 | |
| 8119 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8121 | |
| 8122 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8123 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8124 | |
| 8125 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8126 | EXPECT_EQ(200, response->headers->response_code()); |
| 8127 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8128 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8129 | |
| 8130 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8131 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8132 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8133 | LoadTimingInfo load_timing_info; |
| 8134 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8135 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8136 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8137 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8138 | trans.reset(); |
| 8139 | session->CloseAllConnections(); |
| 8140 | } |
| 8141 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8142 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8143 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8144 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8145 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8146 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8147 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8148 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8149 | HttpRequestInfo request; |
| 8150 | HttpRequestInfo push_request; |
| 8151 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8153 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8154 | push_request.method = "GET"; |
| 8155 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8156 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8157 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8158 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8159 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8160 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8161 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8162 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8163 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8164 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8166 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8167 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8168 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8169 | SpdySerializedFrame stream2_priority( |
| 8170 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8171 | |
| 8172 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8173 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8174 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8175 | }; |
| 8176 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8177 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8178 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8179 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8180 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8181 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8182 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8183 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8184 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8185 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8186 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8187 | |
| 8188 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8189 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8190 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8191 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8192 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8193 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8194 | }; |
| 8195 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8196 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8197 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8198 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8199 | // Negotiate SPDY to the proxy |
| 8200 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8201 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8204 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8206 | TestCompletionCallback callback; |
| 8207 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8209 | |
| 8210 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8211 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8212 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8214 | std::unique_ptr<HttpNetworkTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8216 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8218 | |
| 8219 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8221 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8222 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8223 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8224 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8225 | |
| 8226 | EXPECT_EQ(200, response->headers->response_code()); |
| 8227 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8228 | |
| 8229 | std::string response_data; |
| 8230 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8231 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8232 | EXPECT_EQ("hello!", response_data); |
| 8233 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8234 | LoadTimingInfo load_timing_info; |
| 8235 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8236 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8237 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8238 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8239 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8240 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8241 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8242 | |
| 8243 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8245 | EXPECT_EQ("pushed", response_data); |
| 8246 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8247 | LoadTimingInfo push_load_timing_info; |
| 8248 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8249 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8250 | // The transactions should share a socket ID, despite being for different |
| 8251 | // origins. |
| 8252 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8253 | push_load_timing_info.socket_log_id); |
| 8254 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8255 | trans.reset(); |
| 8256 | push_trans.reset(); |
| 8257 | session->CloseAllConnections(); |
| 8258 | } |
| 8259 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8260 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8261 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8262 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8263 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8264 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8265 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8266 | HttpRequestInfo request; |
| 8267 | |
| 8268 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8269 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8270 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8271 | session_deps_.proxy_service = |
| 8272 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8273 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8274 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8275 | |
| 8276 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8277 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8278 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8280 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8281 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8282 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8283 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8284 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8285 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8286 | |
| 8287 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8288 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8289 | }; |
| 8290 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8291 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8292 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8293 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8294 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8295 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8296 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8297 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8298 | |
| 8299 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8300 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8301 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8302 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8303 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8304 | }; |
| 8305 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8306 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8307 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8308 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8309 | // Negotiate SPDY to the proxy |
| 8310 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8311 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8313 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8314 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8315 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8316 | TestCompletionCallback callback; |
| 8317 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8319 | |
| 8320 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8321 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8322 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8323 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8324 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8325 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8326 | |
| 8327 | EXPECT_EQ(200, response->headers->response_code()); |
| 8328 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8329 | |
| 8330 | std::string response_data; |
| 8331 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8333 | EXPECT_EQ("hello!", response_data); |
| 8334 | |
| 8335 | trans.reset(); |
| 8336 | session->CloseAllConnections(); |
| 8337 | } |
| 8338 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8339 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8340 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8341 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8342 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8343 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8344 | proxy_delegate->set_trusted_spdy_proxy( |
| 8345 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8346 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8347 | HttpRequestInfo request; |
| 8348 | |
| 8349 | request.method = "GET"; |
| 8350 | request.url = GURL("http://www.example.org/"); |
| 8351 | |
| 8352 | // Configure against https proxy server "myproxy:70". |
| 8353 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8354 | BoundTestNetLog log; |
| 8355 | session_deps_.net_log = log.bound().net_log(); |
| 8356 | |
| 8357 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8358 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8359 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8361 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8362 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8363 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8364 | SpdySerializedFrame stream2_priority( |
| 8365 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8366 | |
| 8367 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8368 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8369 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8370 | }; |
| 8371 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8372 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8373 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8374 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8375 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8376 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8377 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8378 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8379 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8380 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8381 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8382 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8383 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8384 | |
| 8385 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8386 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8387 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8388 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8389 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8390 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8391 | }; |
| 8392 | |
| 8393 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8394 | arraysize(spdy_writes)); |
| 8395 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8396 | // Negotiate SPDY to the proxy |
| 8397 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8398 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8401 | std::unique_ptr<HttpNetworkTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8402 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8403 | TestCompletionCallback callback; |
| 8404 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8405 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8406 | |
| 8407 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8408 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8409 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8410 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8411 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8412 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8413 | |
| 8414 | EXPECT_EQ(200, response->headers->response_code()); |
| 8415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8416 | |
| 8417 | std::string response_data; |
| 8418 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8419 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8420 | EXPECT_EQ("hello!", response_data); |
| 8421 | |
| 8422 | trans.reset(); |
| 8423 | session->CloseAllConnections(); |
| 8424 | } |
| 8425 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8426 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8427 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8428 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8429 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8430 | |
| 8431 | HttpRequestInfo request; |
| 8432 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8433 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8434 | |
| 8435 | // Attempt to fetch the URL from a server with a bad cert |
| 8436 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8437 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8438 | "Host: www.example.org:443\r\n" |
| 8439 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8440 | }; |
| 8441 | |
| 8442 | MockRead bad_cert_reads[] = { |
| 8443 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8445 | }; |
| 8446 | |
| 8447 | // Attempt to fetch the URL with a good cert |
| 8448 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8449 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8450 | "Host: www.example.org:443\r\n" |
| 8451 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8452 | MockWrite("GET / HTTP/1.1\r\n" |
| 8453 | "Host: www.example.org\r\n" |
| 8454 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8455 | }; |
| 8456 | |
| 8457 | MockRead good_cert_reads[] = { |
| 8458 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8459 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8460 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8461 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8462 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8463 | }; |
| 8464 | |
| 8465 | StaticSocketDataProvider ssl_bad_certificate( |
| 8466 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8467 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8468 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8469 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8470 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8471 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8472 | |
| 8473 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8475 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8477 | |
| 8478 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8480 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8483 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8484 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8486 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8490 | |
| 8491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8492 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8494 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8495 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8496 | |
| 8497 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8498 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8500 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8501 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8502 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8503 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8504 | } |
| 8505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8506 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8507 | HttpRequestInfo request; |
| 8508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8509 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8510 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8511 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8515 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8516 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8517 | MockWrite( |
| 8518 | "GET / HTTP/1.1\r\n" |
| 8519 | "Host: www.example.org\r\n" |
| 8520 | "Connection: keep-alive\r\n" |
| 8521 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8522 | }; |
| 8523 | |
| 8524 | // Lastly, the server responds with the actual content. |
| 8525 | MockRead data_reads[] = { |
| 8526 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8527 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8528 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8529 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8530 | }; |
| 8531 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8532 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8533 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8536 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8538 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8540 | |
| 8541 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8542 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8543 | } |
| 8544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8545 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8546 | HttpRequestInfo request; |
| 8547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8548 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8549 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8550 | "Chromium Ultra Awesome X Edition"); |
| 8551 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8552 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8555 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8556 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8557 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8558 | "Host: www.example.org:443\r\n" |
| 8559 | "Proxy-Connection: keep-alive\r\n" |
| 8560 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8561 | }; |
| 8562 | MockRead data_reads[] = { |
| 8563 | // Return an error, so the transaction stops here (this test isn't |
| 8564 | // interested in the rest). |
| 8565 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8566 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8567 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8568 | }; |
| 8569 | |
| 8570 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8571 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8574 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8578 | |
| 8579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8581 | } |
| 8582 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8583 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8584 | HttpRequestInfo request; |
| 8585 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8586 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8587 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8588 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8592 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8593 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8594 | MockWrite( |
| 8595 | "GET / HTTP/1.1\r\n" |
| 8596 | "Host: www.example.org\r\n" |
| 8597 | "Connection: keep-alive\r\n" |
| 8598 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8599 | }; |
| 8600 | |
| 8601 | // Lastly, the server responds with the actual content. |
| 8602 | MockRead data_reads[] = { |
| 8603 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8604 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8605 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8606 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8607 | }; |
| 8608 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8609 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8610 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8613 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8617 | |
| 8618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8619 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8620 | } |
| 8621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8622 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | HttpRequestInfo request; |
| 8624 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8625 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8629 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8630 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8631 | MockWrite( |
| 8632 | "POST / HTTP/1.1\r\n" |
| 8633 | "Host: www.example.org\r\n" |
| 8634 | "Connection: keep-alive\r\n" |
| 8635 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8636 | }; |
| 8637 | |
| 8638 | // Lastly, the server responds with the actual content. |
| 8639 | MockRead data_reads[] = { |
| 8640 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8641 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8642 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8643 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8644 | }; |
| 8645 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8646 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8647 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8648 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8650 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8651 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8652 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8654 | |
| 8655 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8656 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8657 | } |
| 8658 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8659 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8660 | HttpRequestInfo request; |
| 8661 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8662 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8663 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8665 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8666 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8667 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8668 | MockWrite( |
| 8669 | "PUT / HTTP/1.1\r\n" |
| 8670 | "Host: www.example.org\r\n" |
| 8671 | "Connection: keep-alive\r\n" |
| 8672 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8673 | }; |
| 8674 | |
| 8675 | // Lastly, the server responds with the actual content. |
| 8676 | MockRead data_reads[] = { |
| 8677 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8678 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8679 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8681 | }; |
| 8682 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8683 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8684 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8687 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8689 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8691 | |
| 8692 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8693 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8694 | } |
| 8695 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8696 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8697 | HttpRequestInfo request; |
| 8698 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8699 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8703 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8704 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8705 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8706 | "Host: www.example.org\r\n" |
| 8707 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8708 | }; |
| 8709 | |
| 8710 | // Lastly, the server responds with the actual content. |
| 8711 | MockRead data_reads[] = { |
| 8712 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8713 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8714 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8716 | }; |
| 8717 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8718 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8719 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8720 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8722 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8724 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8726 | |
| 8727 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8729 | } |
| 8730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8731 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8732 | HttpRequestInfo request; |
| 8733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8734 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8735 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8739 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8740 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8741 | MockWrite( |
| 8742 | "GET / HTTP/1.1\r\n" |
| 8743 | "Host: www.example.org\r\n" |
| 8744 | "Connection: keep-alive\r\n" |
| 8745 | "Pragma: no-cache\r\n" |
| 8746 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8747 | }; |
| 8748 | |
| 8749 | // Lastly, the server responds with the actual content. |
| 8750 | MockRead data_reads[] = { |
| 8751 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8753 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8755 | }; |
| 8756 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8757 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8758 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8761 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8763 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8765 | |
| 8766 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8767 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8768 | } |
| 8769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8770 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8771 | HttpRequestInfo request; |
| 8772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8773 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8774 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8778 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8779 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8780 | MockWrite( |
| 8781 | "GET / HTTP/1.1\r\n" |
| 8782 | "Host: www.example.org\r\n" |
| 8783 | "Connection: keep-alive\r\n" |
| 8784 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8785 | }; |
| 8786 | |
| 8787 | // Lastly, the server responds with the actual content. |
| 8788 | MockRead data_reads[] = { |
| 8789 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8790 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8791 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8792 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8793 | }; |
| 8794 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8795 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8796 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8799 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8803 | |
| 8804 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8806 | } |
| 8807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8808 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8809 | HttpRequestInfo request; |
| 8810 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8811 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8812 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8816 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8817 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8818 | MockWrite( |
| 8819 | "GET / HTTP/1.1\r\n" |
| 8820 | "Host: www.example.org\r\n" |
| 8821 | "Connection: keep-alive\r\n" |
| 8822 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8823 | }; |
| 8824 | |
| 8825 | // Lastly, the server responds with the actual content. |
| 8826 | MockRead data_reads[] = { |
| 8827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8829 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8830 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8831 | }; |
| 8832 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8833 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8834 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8837 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8841 | |
| 8842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8844 | } |
| 8845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8846 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8847 | HttpRequestInfo request; |
| 8848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8849 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8850 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8851 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8852 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8853 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8856 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8857 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8858 | MockWrite( |
| 8859 | "GET / HTTP/1.1\r\n" |
| 8860 | "Host: www.example.org\r\n" |
| 8861 | "Connection: keep-alive\r\n" |
| 8862 | "referer: www.foo.com\r\n" |
| 8863 | "hEllo: Kitty\r\n" |
| 8864 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8865 | }; |
| 8866 | |
| 8867 | // Lastly, the server responds with the actual content. |
| 8868 | MockRead data_reads[] = { |
| 8869 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8870 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8871 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8873 | }; |
| 8874 | |
| 8875 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8876 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8879 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8880 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8881 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8883 | |
| 8884 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8885 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8886 | } |
| 8887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8888 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8889 | HttpRequestInfo request; |
| 8890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8891 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8892 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8893 | session_deps_.proxy_service = |
| 8894 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8895 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8896 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8897 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8898 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8899 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8900 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8901 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8902 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8903 | |
| 8904 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8905 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8906 | MockWrite( |
| 8907 | "GET / HTTP/1.1\r\n" |
| 8908 | "Host: www.example.org\r\n" |
| 8909 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8910 | |
| 8911 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8912 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8913 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8915 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8916 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8917 | }; |
| 8918 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8919 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8920 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8921 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8923 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8924 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8927 | |
| 8928 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8931 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8932 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8933 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8934 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8935 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8936 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8937 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8938 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8939 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8940 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8941 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8942 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8943 | EXPECT_EQ("Payload", response_text); |
| 8944 | } |
| 8945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8946 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8947 | HttpRequestInfo request; |
| 8948 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8949 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8950 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8951 | session_deps_.proxy_service = |
| 8952 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8953 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8954 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8955 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8958 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8959 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8960 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8961 | |
| 8962 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8963 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8964 | arraysize(write_buffer)), |
| 8965 | MockWrite( |
| 8966 | "GET / HTTP/1.1\r\n" |
| 8967 | "Host: www.example.org\r\n" |
| 8968 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8969 | |
| 8970 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8971 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8972 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8973 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8974 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8975 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8976 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8977 | }; |
| 8978 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8979 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8980 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8982 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8983 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8986 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8987 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8988 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8990 | |
| 8991 | rv = callback.WaitForResult(); |
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 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8994 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8995 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8996 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8997 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9000 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9001 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9002 | |
| 9003 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9004 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9006 | EXPECT_EQ("Payload", response_text); |
| 9007 | } |
| 9008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9009 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9010 | HttpRequestInfo request; |
| 9011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9012 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9013 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9014 | session_deps_.proxy_service = |
| 9015 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9016 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9017 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9020 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9021 | |
| 9022 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9023 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9024 | |
| 9025 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9026 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9027 | MockWrite( |
| 9028 | "GET / HTTP/1.1\r\n" |
| 9029 | "Host: www.example.org\r\n" |
| 9030 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9031 | |
| 9032 | MockRead data_reads[] = { |
| 9033 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9034 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9035 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9036 | MockRead("Payload"), |
| 9037 | MockRead(SYNCHRONOUS, OK) |
| 9038 | }; |
| 9039 | |
| 9040 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9041 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9042 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9043 | |
| 9044 | TestCompletionCallback callback; |
| 9045 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9046 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9047 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9048 | |
| 9049 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9050 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9052 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9053 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9054 | |
| 9055 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9056 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9057 | TestLoadTimingNotReused(load_timing_info, |
| 9058 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9059 | |
| 9060 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9061 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9063 | EXPECT_EQ("Payload", response_text); |
| 9064 | } |
| 9065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9066 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9067 | HttpRequestInfo request; |
| 9068 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9069 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9070 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9071 | session_deps_.proxy_service = |
| 9072 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9073 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9074 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9078 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9079 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9080 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9081 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9082 | 0x05, // Version |
| 9083 | 0x01, // Command (CONNECT) |
| 9084 | 0x00, // Reserved. |
| 9085 | 0x03, // Address type (DOMAINNAME). |
| 9086 | 0x0F, // Length of domain (15) |
| 9087 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9088 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9089 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9090 | const char kSOCKS5OkResponse[] = |
| 9091 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9092 | |
| 9093 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9094 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9095 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9096 | MockWrite( |
| 9097 | "GET / HTTP/1.1\r\n" |
| 9098 | "Host: www.example.org\r\n" |
| 9099 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9100 | |
| 9101 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9102 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9103 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9104 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9105 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9106 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9107 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9108 | }; |
| 9109 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9110 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9111 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9114 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9116 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9118 | |
| 9119 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9122 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9123 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9124 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9125 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9126 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9127 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9128 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9129 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9130 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9131 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9132 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9134 | EXPECT_EQ("Payload", response_text); |
| 9135 | } |
| 9136 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9137 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9138 | HttpRequestInfo request; |
| 9139 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9140 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9141 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9142 | session_deps_.proxy_service = |
| 9143 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9144 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9145 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9146 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9147 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9148 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9149 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9150 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9151 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9152 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9153 | 0x05, // Version |
| 9154 | 0x01, // Command (CONNECT) |
| 9155 | 0x00, // Reserved. |
| 9156 | 0x03, // Address type (DOMAINNAME). |
| 9157 | 0x0F, // Length of domain (15) |
| 9158 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9159 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9160 | }; |
| 9161 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9162 | const char kSOCKS5OkResponse[] = |
| 9163 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9164 | |
| 9165 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9166 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9167 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9168 | arraysize(kSOCKS5OkRequest)), |
| 9169 | MockWrite( |
| 9170 | "GET / HTTP/1.1\r\n" |
| 9171 | "Host: www.example.org\r\n" |
| 9172 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9173 | |
| 9174 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9175 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9176 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9177 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9178 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9179 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9180 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9181 | }; |
| 9182 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9183 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9184 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9186 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9187 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9190 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9191 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9192 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9194 | |
| 9195 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9198 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9199 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9200 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9201 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9202 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9203 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9204 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9205 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9206 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9207 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9208 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9209 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9210 | EXPECT_EQ("Payload", response_text); |
| 9211 | } |
| 9212 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9213 | namespace { |
| 9214 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9215 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9216 | |
| 9217 | struct GroupNameTest { |
| 9218 | std::string proxy_server; |
| 9219 | std::string url; |
| 9220 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9221 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9222 | }; |
| 9223 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9224 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9225 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9226 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9227 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9228 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9229 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9230 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9231 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9232 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9233 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9234 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9235 | |
| 9236 | return session; |
| 9237 | } |
| 9238 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9239 | int GroupNameTransactionHelper(const std::string& url, |
| 9240 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9241 | HttpRequestInfo request; |
| 9242 | request.method = "GET"; |
| 9243 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9247 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9248 | |
| 9249 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9250 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9251 | } |
| 9252 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9253 | } // namespace |
| 9254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9255 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9256 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9257 | { |
| 9258 | "", // unused |
| 9259 | "http://www.example.org/direct", |
| 9260 | "www.example.org:80", |
| 9261 | false, |
| 9262 | }, |
| 9263 | { |
| 9264 | "", // unused |
| 9265 | "http://[2001:1418:13:1::25]/direct", |
| 9266 | "[2001:1418:13:1::25]:80", |
| 9267 | false, |
| 9268 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9269 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9270 | // SSL Tests |
| 9271 | { |
| 9272 | "", // unused |
| 9273 | "https://www.example.org/direct_ssl", |
| 9274 | "ssl/www.example.org:443", |
| 9275 | true, |
| 9276 | }, |
| 9277 | { |
| 9278 | "", // unused |
| 9279 | "https://[2001:1418:13:1::25]/direct", |
| 9280 | "ssl/[2001:1418:13:1::25]:443", |
| 9281 | true, |
| 9282 | }, |
| 9283 | { |
| 9284 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9285 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9286 | "ssl/host.with.alternate:443", |
| 9287 | true, |
| 9288 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9289 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9290 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9291 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9292 | session_deps_.proxy_service = |
| 9293 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9294 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9295 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9296 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9297 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9298 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9299 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9300 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9301 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9302 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9303 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9304 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9305 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9306 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9307 | |
| 9308 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9309 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9310 | if (tests[i].ssl) |
| 9311 | EXPECT_EQ(tests[i].expected_group_name, |
| 9312 | ssl_conn_pool->last_group_name_received()); |
| 9313 | else |
| 9314 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9315 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9316 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9317 | } |
| 9318 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9319 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9320 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9321 | { |
| 9322 | "http_proxy", |
| 9323 | "http://www.example.org/http_proxy_normal", |
| 9324 | "www.example.org:80", |
| 9325 | false, |
| 9326 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9327 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9328 | // SSL Tests |
| 9329 | { |
| 9330 | "http_proxy", |
| 9331 | "https://www.example.org/http_connect_ssl", |
| 9332 | "ssl/www.example.org:443", |
| 9333 | true, |
| 9334 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9336 | { |
| 9337 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9338 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9339 | "ssl/host.with.alternate:443", |
| 9340 | true, |
| 9341 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9342 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9343 | { |
| 9344 | "http_proxy", |
| 9345 | "ftp://ftp.google.com/http_proxy_normal", |
| 9346 | "ftp/ftp.google.com:21", |
| 9347 | false, |
| 9348 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9349 | }; |
| 9350 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9351 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9352 | session_deps_.proxy_service = |
| 9353 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9354 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9355 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9356 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9357 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9358 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9359 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9360 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9361 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9362 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9363 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9364 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9365 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9366 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9367 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9368 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9369 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9370 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9371 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9372 | |
| 9373 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9374 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9375 | if (tests[i].ssl) |
| 9376 | EXPECT_EQ(tests[i].expected_group_name, |
| 9377 | ssl_conn_pool->last_group_name_received()); |
| 9378 | else |
| 9379 | EXPECT_EQ(tests[i].expected_group_name, |
| 9380 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9381 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9382 | } |
| 9383 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9384 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9385 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9386 | { |
| 9387 | "socks4://socks_proxy:1080", |
| 9388 | "http://www.example.org/socks4_direct", |
| 9389 | "socks4/www.example.org:80", |
| 9390 | false, |
| 9391 | }, |
| 9392 | { |
| 9393 | "socks5://socks_proxy:1080", |
| 9394 | "http://www.example.org/socks5_direct", |
| 9395 | "socks5/www.example.org:80", |
| 9396 | false, |
| 9397 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9398 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9399 | // SSL Tests |
| 9400 | { |
| 9401 | "socks4://socks_proxy:1080", |
| 9402 | "https://www.example.org/socks4_ssl", |
| 9403 | "socks4/ssl/www.example.org:443", |
| 9404 | true, |
| 9405 | }, |
| 9406 | { |
| 9407 | "socks5://socks_proxy:1080", |
| 9408 | "https://www.example.org/socks5_ssl", |
| 9409 | "socks5/ssl/www.example.org:443", |
| 9410 | true, |
| 9411 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9412 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9413 | { |
| 9414 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9415 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9416 | "socks4/ssl/host.with.alternate:443", |
| 9417 | true, |
| 9418 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9419 | }; |
| 9420 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9421 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9422 | session_deps_.proxy_service = |
| 9423 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9424 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9425 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9426 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9427 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9428 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9429 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9430 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9431 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9432 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9433 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9434 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9435 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9436 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9437 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9438 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9439 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9440 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9441 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9444 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9445 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9446 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9447 | if (tests[i].ssl) |
| 9448 | EXPECT_EQ(tests[i].expected_group_name, |
| 9449 | ssl_conn_pool->last_group_name_received()); |
| 9450 | else |
| 9451 | EXPECT_EQ(tests[i].expected_group_name, |
| 9452 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9453 | } |
| 9454 | } |
| 9455 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9456 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9457 | HttpRequestInfo request; |
| 9458 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9459 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9460 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9461 | session_deps_.proxy_service = |
| 9462 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9463 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9464 | // This simulates failure resolving all hostnames; that means we will fail |
| 9465 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9466 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9471 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9472 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9473 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9475 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9476 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9477 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9478 | } |
| 9479 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9480 | // Base test to make sure that when the load flags for a request specify to |
| 9481 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9482 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9483 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9484 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9485 | HttpRequestInfo request_info; |
| 9486 | request_info.method = "GET"; |
| 9487 | request_info.load_flags = load_flags; |
| 9488 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9489 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9490 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9491 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9492 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9493 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9495 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9496 | // 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] | 9497 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9498 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9499 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9500 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9501 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9502 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9503 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9505 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9506 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9507 | |
| 9508 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9509 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9510 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9511 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9512 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9513 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9514 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9515 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9516 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9517 | // 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] | 9518 | // we can tell if the next lookup hit the cache, or the "network". |
| 9519 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9520 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9521 | |
| 9522 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9523 | // 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] | 9524 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9526 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9527 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9528 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9529 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9530 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9531 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9532 | |
| 9533 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9534 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9535 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9536 | } |
| 9537 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9538 | // There are multiple load flags that should trigger the host cache bypass. |
| 9539 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9540 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9541 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9542 | } |
| 9543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9544 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9545 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9546 | } |
| 9547 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9548 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9549 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9550 | } |
| 9551 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9552 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9553 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9554 | HttpRequestInfo request; |
| 9555 | request.method = "GET"; |
| 9556 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9557 | |
| 9558 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9559 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9560 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9561 | StaticSocketDataProvider data(NULL, 0, |
| 9562 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9563 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9566 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9569 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9570 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9572 | |
| 9573 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9574 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9575 | |
| 9576 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9577 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9578 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9579 | } |
| 9580 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9581 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9582 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9583 | HttpRequestInfo request; |
| 9584 | request.method = "GET"; |
| 9585 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9586 | |
| 9587 | MockRead data_reads[] = { |
| 9588 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9590 | }; |
| 9591 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9596 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9599 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9600 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9602 | |
| 9603 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9604 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9606 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9607 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9608 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9609 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9610 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9611 | |
| 9612 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9613 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9614 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9615 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9616 | |
| 9617 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9618 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9619 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9620 | } |
| 9621 | |
| 9622 | // Make sure that a dropped connection while draining the body for auth |
| 9623 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9624 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9625 | HttpRequestInfo request; |
| 9626 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9627 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9628 | |
| 9629 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9630 | MockWrite( |
| 9631 | "GET / HTTP/1.1\r\n" |
| 9632 | "Host: www.example.org\r\n" |
| 9633 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9634 | }; |
| 9635 | |
| 9636 | MockRead data_reads1[] = { |
| 9637 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9638 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9639 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9640 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9641 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9642 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9643 | }; |
| 9644 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9645 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9646 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9647 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9649 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9650 | // be issuing -- the final header line contains the credentials. |
| 9651 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9652 | MockWrite( |
| 9653 | "GET / HTTP/1.1\r\n" |
| 9654 | "Host: www.example.org\r\n" |
| 9655 | "Connection: keep-alive\r\n" |
| 9656 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9657 | }; |
| 9658 | |
| 9659 | // Lastly, the server responds with the actual content. |
| 9660 | MockRead data_reads2[] = { |
| 9661 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9662 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9663 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9665 | }; |
| 9666 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9667 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9668 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9669 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9672 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9676 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
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 = callback1.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 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9683 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9684 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9686 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9688 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9690 | |
| 9691 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9692 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9694 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9695 | ASSERT_TRUE(response); |
| 9696 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9697 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9698 | } |
| 9699 | |
| 9700 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9701 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9702 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9703 | |
| 9704 | HttpRequestInfo request; |
| 9705 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9706 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9707 | |
| 9708 | MockRead proxy_reads[] = { |
| 9709 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9710 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9711 | }; |
| 9712 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9713 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9714 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9715 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9716 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9719 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9720 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9721 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9725 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9726 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9728 | |
| 9729 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9730 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9731 | } |
| 9732 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9733 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9734 | HttpRequestInfo request; |
| 9735 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9736 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9740 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9741 | MockRead data_reads[] = { |
| 9742 | 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] | 9743 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9744 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9745 | |
| 9746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9749 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9750 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9751 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9753 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9754 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9756 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9757 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9758 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9759 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9760 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9761 | |
| 9762 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9763 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9764 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9765 | } |
| 9766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9767 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9768 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9769 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9770 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9771 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9772 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9774 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9775 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9776 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9777 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9778 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9779 | |
| 9780 | HttpRequestInfo request; |
| 9781 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9782 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9783 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9787 | |
| 9788 | MockRead data_reads[] = { |
| 9789 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9790 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9792 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9793 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9794 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9796 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9800 | |
| 9801 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9802 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9804 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9805 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9806 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9807 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9808 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9809 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9810 | } |
| 9811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9812 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9813 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9814 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9815 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9816 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9817 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9818 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9819 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9820 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9821 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9822 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9823 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9824 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9825 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9826 | |
| 9827 | HttpRequestInfo request; |
| 9828 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9830 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9831 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9832 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9835 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9836 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9839 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9840 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9841 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9843 | |
| 9844 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9845 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9846 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9847 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9848 | } |
| 9849 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9850 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9851 | class FakeUploadElementReader : public UploadElementReader { |
| 9852 | public: |
| 9853 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9854 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9855 | |
| 9856 | const CompletionCallback& callback() const { return callback_; } |
| 9857 | |
| 9858 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9859 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9860 | callback_ = callback; |
| 9861 | return ERR_IO_PENDING; |
| 9862 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9863 | uint64_t GetContentLength() const override { return 0; } |
| 9864 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9865 | int Read(IOBuffer* buf, |
| 9866 | int buf_length, |
| 9867 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9868 | return ERR_FAILED; |
| 9869 | } |
| 9870 | |
| 9871 | private: |
| 9872 | CompletionCallback callback_; |
| 9873 | }; |
| 9874 | |
| 9875 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9876 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9877 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9878 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9879 | |
| 9880 | HttpRequestInfo request; |
| 9881 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9882 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9883 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9884 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9886 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9887 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9888 | |
| 9889 | StaticSocketDataProvider data; |
| 9890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9891 | |
| 9892 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9893 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9895 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9896 | |
| 9897 | // Transaction is pending on request body initialization. |
| 9898 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9899 | |
| 9900 | // Return Init()'s result after the transaction gets destroyed. |
| 9901 | trans.reset(); |
| 9902 | fake_reader->callback().Run(OK); // Should not crash. |
| 9903 | } |
| 9904 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9905 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9906 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9907 | HttpRequestInfo request; |
| 9908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9909 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9910 | |
| 9911 | // First transaction will request a resource and receive a Basic challenge |
| 9912 | // with realm="first_realm". |
| 9913 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9914 | MockWrite( |
| 9915 | "GET / HTTP/1.1\r\n" |
| 9916 | "Host: www.example.org\r\n" |
| 9917 | "Connection: keep-alive\r\n" |
| 9918 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9919 | }; |
| 9920 | MockRead data_reads1[] = { |
| 9921 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9922 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9923 | "\r\n"), |
| 9924 | }; |
| 9925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9926 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9927 | // for first_realm. The server will reject and provide a challenge with |
| 9928 | // second_realm. |
| 9929 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9930 | MockWrite( |
| 9931 | "GET / HTTP/1.1\r\n" |
| 9932 | "Host: www.example.org\r\n" |
| 9933 | "Connection: keep-alive\r\n" |
| 9934 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9935 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9936 | }; |
| 9937 | MockRead data_reads2[] = { |
| 9938 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9939 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9940 | "\r\n"), |
| 9941 | }; |
| 9942 | |
| 9943 | // This again fails, and goes back to first_realm. Make sure that the |
| 9944 | // entry is removed from cache. |
| 9945 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9946 | MockWrite( |
| 9947 | "GET / HTTP/1.1\r\n" |
| 9948 | "Host: www.example.org\r\n" |
| 9949 | "Connection: keep-alive\r\n" |
| 9950 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9951 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9952 | }; |
| 9953 | MockRead data_reads3[] = { |
| 9954 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9955 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9956 | "\r\n"), |
| 9957 | }; |
| 9958 | |
| 9959 | // Try one last time (with the correct password) and get the resource. |
| 9960 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9961 | MockWrite( |
| 9962 | "GET / HTTP/1.1\r\n" |
| 9963 | "Host: www.example.org\r\n" |
| 9964 | "Connection: keep-alive\r\n" |
| 9965 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9966 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9967 | }; |
| 9968 | MockRead data_reads4[] = { |
| 9969 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9970 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9971 | "Content-Length: 5\r\n" |
| 9972 | "\r\n" |
| 9973 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9974 | }; |
| 9975 | |
| 9976 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9977 | data_writes1, arraysize(data_writes1)); |
| 9978 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9979 | data_writes2, arraysize(data_writes2)); |
| 9980 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9981 | data_writes3, arraysize(data_writes3)); |
| 9982 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9983 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9984 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9986 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9987 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9989 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9990 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9991 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9992 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9993 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9994 | // Issue the first request with Authorize headers. There should be a |
| 9995 | // password prompt for first_realm waiting to be filled in after the |
| 9996 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9997 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9999 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10000 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10001 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10002 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10003 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10004 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10005 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10006 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10007 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10008 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10009 | |
| 10010 | // Issue the second request with an incorrect password. There should be a |
| 10011 | // password prompt for second_realm waiting to be filled in after the |
| 10012 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10013 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10014 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10015 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10017 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10018 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10019 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10020 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10021 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10022 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10023 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10024 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10025 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10026 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10027 | |
| 10028 | // Issue the third request with another incorrect password. There should be |
| 10029 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10030 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10031 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10032 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10033 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10034 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10036 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10037 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10038 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10039 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10040 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10041 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10042 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10043 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10044 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10045 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10046 | |
| 10047 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10048 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10049 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10050 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10051 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10052 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10053 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10054 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10055 | ASSERT_TRUE(response); |
| 10056 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10057 | } |
| 10058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10059 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10060 | MockRead data_reads[] = { |
| 10061 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10062 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10063 | MockRead("\r\n"), |
| 10064 | MockRead("hello world"), |
| 10065 | MockRead(SYNCHRONOUS, OK), |
| 10066 | }; |
| 10067 | |
| 10068 | HttpRequestInfo request; |
| 10069 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10070 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10071 | |
| 10072 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10073 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10074 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10075 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10076 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10077 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10078 | TestCompletionCallback callback; |
| 10079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10081 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10082 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10083 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10085 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10086 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10087 | HttpServerProperties* http_server_properties = |
| 10088 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10089 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10090 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10091 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10092 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10093 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10095 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10096 | ASSERT_TRUE(response); |
| 10097 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10098 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10099 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10100 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10101 | |
| 10102 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10103 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10104 | EXPECT_EQ("hello world", response_data); |
| 10105 | |
| 10106 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10107 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10108 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10109 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10110 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10111 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10112 | } |
| 10113 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10114 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10115 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10116 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10117 | MockRead data_reads[] = { |
| 10118 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10119 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10120 | MockRead("\r\n"), |
| 10121 | MockRead("hello world"), |
| 10122 | MockRead(SYNCHRONOUS, OK), |
| 10123 | }; |
| 10124 | |
| 10125 | HttpRequestInfo request; |
| 10126 | request.method = "GET"; |
| 10127 | request.url = GURL("http://www.example.org/"); |
| 10128 | request.load_flags = 0; |
| 10129 | |
| 10130 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10132 | |
| 10133 | TestCompletionCallback callback; |
| 10134 | |
| 10135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10136 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10137 | |
| 10138 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10139 | HttpServerProperties* http_server_properties = |
| 10140 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10141 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10142 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10143 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10144 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10145 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10147 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10149 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10150 | ASSERT_TRUE(response); |
| 10151 | ASSERT_TRUE(response->headers); |
| 10152 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10153 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10154 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10155 | |
| 10156 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10157 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10158 | EXPECT_EQ("hello world", response_data); |
| 10159 | |
| 10160 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10161 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10162 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10163 | } |
| 10164 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10165 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10166 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10167 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10168 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10169 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10170 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10171 | HttpRequestInfo request; |
| 10172 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10173 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10174 | request.load_flags = 0; |
| 10175 | |
| 10176 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10177 | StaticSocketDataProvider first_data; |
| 10178 | first_data.set_connect_data(mock_connect); |
| 10179 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10180 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10181 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10183 | |
| 10184 | MockRead data_reads[] = { |
| 10185 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10186 | MockRead(ASYNC, OK), |
| 10187 | }; |
| 10188 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10189 | 0); |
| 10190 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10191 | |
| 10192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10193 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10194 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10195 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10196 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10197 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10198 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10199 | http_server_properties->SetAlternativeService( |
| 10200 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10203 | TestCompletionCallback callback; |
| 10204 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10205 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10206 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10207 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10208 | } |
| 10209 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10210 | // Regression test for https://crbug.com/615497: |
| 10211 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10212 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10213 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10214 | HttpRequestInfo request; |
| 10215 | request.method = "GET"; |
| 10216 | request.url = GURL("http://www.example.org/"); |
| 10217 | request.load_flags = 0; |
| 10218 | |
| 10219 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10220 | StaticSocketDataProvider first_data; |
| 10221 | first_data.set_connect_data(mock_connect); |
| 10222 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10223 | |
| 10224 | MockRead data_reads[] = { |
| 10225 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10226 | MockRead(ASYNC, OK), |
| 10227 | }; |
| 10228 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10229 | 0); |
| 10230 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10231 | |
| 10232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10233 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10234 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10235 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10236 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10237 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10238 | http_server_properties->SetAlternativeService( |
| 10239 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10242 | TestCompletionCallback callback; |
| 10243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10244 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10245 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10246 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10247 | } |
| 10248 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10249 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10250 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10251 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10252 | HttpServerProperties* http_server_properties = |
| 10253 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10254 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10255 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10256 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10257 | http_server_properties->SetAlternativeService( |
| 10258 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10259 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10260 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10261 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10262 | |
| 10263 | // Send a clear header. |
| 10264 | MockRead data_reads[] = { |
| 10265 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10266 | MockRead("Alt-Svc: clear\r\n"), |
| 10267 | MockRead("\r\n"), |
| 10268 | MockRead("hello world"), |
| 10269 | MockRead(SYNCHRONOUS, OK), |
| 10270 | }; |
| 10271 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10272 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10273 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10274 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10276 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10277 | HttpRequestInfo request; |
| 10278 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10279 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10280 | |
| 10281 | TestCompletionCallback callback; |
| 10282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10285 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10288 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10289 | ASSERT_TRUE(response); |
| 10290 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10291 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10292 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10293 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10294 | |
| 10295 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10296 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10297 | EXPECT_EQ("hello world", response_data); |
| 10298 | |
| 10299 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10300 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10301 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10302 | } |
| 10303 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10304 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10305 | MockRead data_reads[] = { |
| 10306 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10307 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10308 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10309 | MockRead("hello world"), |
| 10310 | MockRead(SYNCHRONOUS, OK), |
| 10311 | }; |
| 10312 | |
| 10313 | HttpRequestInfo request; |
| 10314 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10315 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10316 | |
| 10317 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10319 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10320 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10322 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10323 | TestCompletionCallback callback; |
| 10324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10327 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10328 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10330 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10331 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10332 | HttpServerProperties* http_server_properties = |
| 10333 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10334 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10335 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10336 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10337 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10338 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10340 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10341 | ASSERT_TRUE(response); |
| 10342 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10343 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10344 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10345 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10346 | |
| 10347 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10348 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10349 | EXPECT_EQ("hello world", response_data); |
| 10350 | |
| 10351 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10352 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10353 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10354 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10355 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10356 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10357 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10358 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10359 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10360 | } |
| 10361 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10362 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10363 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10364 | HostPortPair alternative("alternative.example.org", 443); |
| 10365 | std::string origin_url = "https://origin.example.org:443"; |
| 10366 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10367 | |
| 10368 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10369 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10370 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10372 | |
| 10373 | // HTTP/1.1 data for request. |
| 10374 | MockWrite http_writes[] = { |
| 10375 | MockWrite("GET / HTTP/1.1\r\n" |
| 10376 | "Host: alternative.example.org\r\n" |
| 10377 | "Connection: keep-alive\r\n\r\n"), |
| 10378 | }; |
| 10379 | |
| 10380 | MockRead http_reads[] = { |
| 10381 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10382 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10383 | "Content-Length: 40\r\n\r\n" |
| 10384 | "first HTTP/1.1 response from alternative"), |
| 10385 | }; |
| 10386 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10387 | http_writes, arraysize(http_writes)); |
| 10388 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10389 | |
| 10390 | StaticSocketDataProvider data_refused; |
| 10391 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10392 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10393 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10394 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10396 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10397 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10398 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10399 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10400 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10401 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10402 | // Mark the QUIC alternative service as broken. |
| 10403 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10404 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10405 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10407 | request.method = "GET"; |
| 10408 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10409 | TestCompletionCallback callback; |
| 10410 | NetErrorDetails details; |
| 10411 | EXPECT_FALSE(details.quic_broken); |
| 10412 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10413 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10414 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10415 | EXPECT_TRUE(details.quic_broken); |
| 10416 | } |
| 10417 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10418 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10419 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10420 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10421 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10422 | std::string origin_url = "https://origin.example.org:443"; |
| 10423 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10424 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10425 | |
| 10426 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10427 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10428 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10430 | |
| 10431 | // HTTP/1.1 data for request. |
| 10432 | MockWrite http_writes[] = { |
| 10433 | MockWrite("GET / HTTP/1.1\r\n" |
| 10434 | "Host: alternative1.example.org\r\n" |
| 10435 | "Connection: keep-alive\r\n\r\n"), |
| 10436 | }; |
| 10437 | |
| 10438 | MockRead http_reads[] = { |
| 10439 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10440 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10441 | "Content-Length: 40\r\n\r\n" |
| 10442 | "first HTTP/1.1 response from alternative1"), |
| 10443 | }; |
| 10444 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10445 | http_writes, arraysize(http_writes)); |
| 10446 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10447 | |
| 10448 | StaticSocketDataProvider data_refused; |
| 10449 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10450 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10451 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10452 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10453 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10454 | session->http_server_properties(); |
| 10455 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10456 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10457 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10458 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10459 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10460 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10461 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10462 | expiration); |
| 10463 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10464 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10465 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10466 | expiration); |
| 10467 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10468 | |
| 10469 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10470 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10471 | |
| 10472 | // Mark one of the QUIC alternative service as broken. |
| 10473 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10474 | |
| 10475 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10476 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10477 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10478 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10480 | request.method = "GET"; |
| 10481 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10482 | TestCompletionCallback callback; |
| 10483 | NetErrorDetails details; |
| 10484 | EXPECT_FALSE(details.quic_broken); |
| 10485 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10486 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10487 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10488 | EXPECT_FALSE(details.quic_broken); |
| 10489 | } |
| 10490 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10491 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10492 | HttpRequestInfo request; |
| 10493 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10494 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10495 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10496 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10497 | StaticSocketDataProvider first_data; |
| 10498 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10499 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10500 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10501 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10503 | |
| 10504 | MockRead data_reads[] = { |
| 10505 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10506 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10507 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10508 | }; |
| 10509 | StaticSocketDataProvider second_data( |
| 10510 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10514 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10515 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10516 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10517 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10518 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10519 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10520 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10521 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10522 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10523 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10524 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10525 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10532 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10535 | ASSERT_TRUE(response); |
| 10536 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10538 | |
| 10539 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10540 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10541 | EXPECT_EQ("hello world", response_data); |
| 10542 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10543 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10544 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10545 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10546 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10547 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10548 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10549 | } |
| 10550 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10551 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10552 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10553 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10554 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10555 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | HttpRequestInfo restricted_port_request; |
| 10557 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10558 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10559 | restricted_port_request.load_flags = 0; |
| 10560 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10561 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10562 | StaticSocketDataProvider first_data; |
| 10563 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10564 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10565 | |
| 10566 | MockRead data_reads[] = { |
| 10567 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10568 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10569 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10570 | }; |
| 10571 | StaticSocketDataProvider second_data( |
| 10572 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10573 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10574 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10575 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10579 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10580 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10581 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10582 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10583 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10584 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10585 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10586 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10587 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10588 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10591 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10593 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10594 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10595 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10596 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10597 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10598 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10599 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10600 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10601 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10602 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10603 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10604 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10605 | |
| 10606 | HttpRequestInfo restricted_port_request; |
| 10607 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10608 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10609 | restricted_port_request.load_flags = 0; |
| 10610 | |
| 10611 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10612 | StaticSocketDataProvider first_data; |
| 10613 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10614 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10615 | |
| 10616 | MockRead data_reads[] = { |
| 10617 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10618 | MockRead("hello world"), |
| 10619 | MockRead(ASYNC, OK), |
| 10620 | }; |
| 10621 | StaticSocketDataProvider second_data( |
| 10622 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10624 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10625 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10629 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10630 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10631 | session->http_server_properties(); |
| 10632 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10633 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10634 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10635 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10636 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10637 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10638 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10641 | TestCompletionCallback callback; |
| 10642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10643 | EXPECT_EQ(ERR_IO_PENDING, |
| 10644 | trans.Start(&restricted_port_request, callback.callback(), |
| 10645 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10646 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10647 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10648 | } |
| 10649 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10650 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10651 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10652 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10653 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10654 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10655 | HttpRequestInfo restricted_port_request; |
| 10656 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10657 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10658 | restricted_port_request.load_flags = 0; |
| 10659 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10660 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10661 | StaticSocketDataProvider first_data; |
| 10662 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10663 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10664 | |
| 10665 | MockRead data_reads[] = { |
| 10666 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10667 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10668 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10669 | }; |
| 10670 | StaticSocketDataProvider second_data( |
| 10671 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10672 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10673 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10674 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10678 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10679 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10680 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10681 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10682 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10683 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10684 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10685 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10686 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10687 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10690 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10691 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10692 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10693 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10695 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10697 | } |
| 10698 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10699 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10700 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10701 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10702 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10703 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10704 | HttpRequestInfo unrestricted_port_request; |
| 10705 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10706 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10707 | unrestricted_port_request.load_flags = 0; |
| 10708 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10709 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10710 | StaticSocketDataProvider first_data; |
| 10711 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10712 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10713 | |
| 10714 | MockRead data_reads[] = { |
| 10715 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10716 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10717 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10718 | }; |
| 10719 | StaticSocketDataProvider second_data( |
| 10720 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10721 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10722 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10723 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10727 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10728 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10729 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10730 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10731 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10732 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10733 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10734 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10735 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10736 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10739 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10741 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10742 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10744 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10746 | } |
| 10747 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10748 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10749 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10750 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10751 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10752 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | HttpRequestInfo unrestricted_port_request; |
| 10754 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10755 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10756 | unrestricted_port_request.load_flags = 0; |
| 10757 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10758 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10759 | StaticSocketDataProvider first_data; |
| 10760 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10761 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10762 | |
| 10763 | MockRead data_reads[] = { |
| 10764 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10765 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10766 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10767 | }; |
| 10768 | StaticSocketDataProvider second_data( |
| 10769 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10770 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10771 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10772 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10776 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10777 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10778 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10779 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10780 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10781 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10782 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10783 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10784 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10785 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10788 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10790 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10791 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10793 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10794 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10795 | } |
| 10796 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10797 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10798 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10799 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10800 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10801 | HttpRequestInfo request; |
| 10802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10803 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10804 | |
| 10805 | // The alternate protocol request will error out before we attempt to connect, |
| 10806 | // so only the standard HTTP request will try to connect. |
| 10807 | MockRead data_reads[] = { |
| 10808 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10809 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10810 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10811 | }; |
| 10812 | StaticSocketDataProvider data( |
| 10813 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10817 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10818 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10819 | session->http_server_properties(); |
| 10820 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10821 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10822 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10823 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10824 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10825 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10828 | TestCompletionCallback callback; |
| 10829 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10830 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10832 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10833 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10836 | ASSERT_TRUE(response); |
| 10837 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10838 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10839 | |
| 10840 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10841 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10842 | EXPECT_EQ("hello world", response_data); |
| 10843 | } |
| 10844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10845 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10846 | HttpRequestInfo request; |
| 10847 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10848 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10849 | |
| 10850 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10851 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10852 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10853 | MockRead("\r\n"), |
| 10854 | MockRead("hello world"), |
| 10855 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10856 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10857 | |
| 10858 | StaticSocketDataProvider first_transaction( |
| 10859 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10860 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10861 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10862 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10864 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10865 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10866 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10867 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10868 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10869 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10870 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10871 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10872 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10873 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10874 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10875 | }; |
| 10876 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10877 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10878 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10880 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10881 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10882 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10883 | NULL, 0, NULL, 0); |
| 10884 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10885 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10886 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10887 | &hanging_non_alternate_protocol_socket); |
| 10888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10889 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10892 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10895 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10897 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10898 | |
| 10899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10900 | ASSERT_TRUE(response); |
| 10901 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10903 | |
| 10904 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10905 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10906 | EXPECT_EQ("hello world", response_data); |
| 10907 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10908 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10909 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10910 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10912 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10913 | |
| 10914 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10915 | ASSERT_TRUE(response); |
| 10916 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10917 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10918 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10919 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10920 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10921 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10922 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10923 | } |
| 10924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10925 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10926 | HttpRequestInfo request; |
| 10927 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10928 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10929 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10930 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10931 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10932 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10933 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10934 | MockRead("\r\n"), |
| 10935 | MockRead("hello world"), |
| 10936 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10937 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10938 | }; |
| 10939 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10940 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10941 | 0); |
| 10942 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10943 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10944 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10946 | |
| 10947 | // Second transaction starts an alternative and a non-alternative Job. |
| 10948 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10949 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10950 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10951 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10952 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10953 | |
| 10954 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10955 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10956 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10957 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10958 | // Third transaction starts an alternative and a non-alternative job. |
| 10959 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10960 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10961 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10962 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10963 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10964 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10965 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10966 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10967 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10968 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10969 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10970 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10971 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10972 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10973 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10974 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10975 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10976 | }; |
| 10977 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10978 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10979 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10980 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10981 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10982 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10983 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10984 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10985 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10986 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10987 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10989 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10990 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10991 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10992 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10994 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10995 | |
| 10996 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10997 | ASSERT_TRUE(response); |
| 10998 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10999 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11000 | |
| 11001 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11002 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11003 | EXPECT_EQ("hello world", response_data); |
| 11004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11005 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11006 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11007 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11010 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11011 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11012 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11014 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11015 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11016 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11017 | |
| 11018 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11019 | ASSERT_TRUE(response); |
| 11020 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11021 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11022 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11023 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11024 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11025 | EXPECT_EQ("hello!", response_data); |
| 11026 | |
| 11027 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11028 | ASSERT_TRUE(response); |
| 11029 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11030 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11031 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11032 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11033 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11034 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11035 | } |
| 11036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11037 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11038 | HttpRequestInfo request; |
| 11039 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11040 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11041 | |
| 11042 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11043 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11044 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11045 | MockRead("\r\n"), |
| 11046 | MockRead("hello world"), |
| 11047 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11048 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11049 | }; |
| 11050 | |
| 11051 | StaticSocketDataProvider first_transaction( |
| 11052 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11053 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11054 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11055 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11057 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11058 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11059 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11060 | NULL, 0, NULL, 0); |
| 11061 | hanging_alternate_protocol_socket.set_connect_data( |
| 11062 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11063 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11064 | &hanging_alternate_protocol_socket); |
| 11065 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11066 | // 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] | 11067 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11068 | NULL, 0); |
| 11069 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11070 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11072 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11075 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11077 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11078 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11080 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11081 | |
| 11082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11083 | ASSERT_TRUE(response); |
| 11084 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11085 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11086 | |
| 11087 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11088 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11089 | EXPECT_EQ("hello world", response_data); |
| 11090 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11091 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11092 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11093 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11095 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11096 | |
| 11097 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11098 | ASSERT_TRUE(response); |
| 11099 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11100 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11101 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11102 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11103 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11104 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11105 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11106 | } |
| 11107 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11108 | class CapturingProxyResolver : public ProxyResolver { |
| 11109 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11110 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11111 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11112 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11113 | int GetProxyForURL(const GURL& url, |
| 11114 | ProxyInfo* results, |
| 11115 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11116 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11117 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11118 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11119 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11120 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11121 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11122 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11123 | } |
| 11124 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11125 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11126 | |
| 11127 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11128 | std::vector<GURL> resolved_; |
| 11129 | |
| 11130 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11131 | }; |
| 11132 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11133 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11134 | public: |
| 11135 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11136 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11137 | |
| 11138 | int CreateProxyResolver( |
| 11139 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11140 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11141 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11142 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11143 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11144 | return OK; |
| 11145 | } |
| 11146 | |
| 11147 | private: |
| 11148 | ProxyResolver* resolver_; |
| 11149 | }; |
| 11150 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11151 | // Test that proxy is resolved using the origin url, |
| 11152 | // regardless of the alternative server. |
| 11153 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11154 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11155 | ProxyConfig proxy_config; |
| 11156 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11157 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11158 | auto proxy_config_service = |
| 11159 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11160 | |
| 11161 | CapturingProxyResolver capturing_proxy_resolver; |
| 11162 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11163 | &capturing_proxy_resolver); |
| 11164 | |
| 11165 | TestNetLog net_log; |
| 11166 | |
| 11167 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11168 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11169 | &net_log); |
| 11170 | |
| 11171 | session_deps_.net_log = &net_log; |
| 11172 | |
| 11173 | // Configure alternative service with a hostname that is not bypassed by the |
| 11174 | // proxy. |
| 11175 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11176 | HttpServerProperties* http_server_properties = |
| 11177 | session->http_server_properties(); |
| 11178 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11179 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11180 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 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 | 4283411 | 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 | 4283411 | 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 | 4283411 | 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 | 4283411 | 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 | 4283411 | 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 | 4283411 | 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 { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11559 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11560 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11561 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11562 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11563 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11564 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11565 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11566 | int num_auth_rounds; |
| 11567 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11568 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11569 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11570 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11571 | {__LINE__, |
| 11572 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11573 | AUTH_NONE, |
| 11574 | OK, |
| 11575 | kServer, |
| 11576 | AUTH_NONE, |
| 11577 | OK, |
| 11578 | 1, |
| 11579 | kNoSSL, |
| 11580 | {TestRound(kGet, kSuccess, OK)}}, |
| 11581 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11582 | {__LINE__, |
| 11583 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11584 | AUTH_NONE, |
| 11585 | OK, |
| 11586 | kServer, |
| 11587 | AUTH_SYNC, |
| 11588 | OK, |
| 11589 | 2, |
| 11590 | kNoSSL, |
| 11591 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11592 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11593 | {__LINE__, |
| 11594 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11595 | AUTH_NONE, |
| 11596 | OK, |
| 11597 | kServer, |
| 11598 | AUTH_SYNC, |
| 11599 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11600 | 3, |
| 11601 | kNoSSL, |
| 11602 | {TestRound(kGet, kServerChallenge, OK), |
| 11603 | TestRound(kGet, kServerChallenge, OK), |
| 11604 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11605 | {__LINE__, |
| 11606 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11607 | AUTH_NONE, |
| 11608 | OK, |
| 11609 | kServer, |
| 11610 | AUTH_SYNC, |
| 11611 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11612 | 2, |
| 11613 | kNoSSL, |
| 11614 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11615 | {__LINE__, |
| 11616 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11617 | AUTH_NONE, |
| 11618 | OK, |
| 11619 | kServer, |
| 11620 | AUTH_SYNC, |
| 11621 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11622 | 2, |
| 11623 | kNoSSL, |
| 11624 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11625 | {__LINE__, |
| 11626 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11627 | AUTH_SYNC, |
| 11628 | ERR_FAILED, |
| 11629 | kServer, |
| 11630 | AUTH_NONE, |
| 11631 | OK, |
| 11632 | 2, |
| 11633 | kNoSSL, |
| 11634 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11635 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11636 | {__LINE__, |
| 11637 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11638 | AUTH_ASYNC, |
| 11639 | ERR_FAILED, |
| 11640 | kServer, |
| 11641 | AUTH_NONE, |
| 11642 | OK, |
| 11643 | 2, |
| 11644 | kNoSSL, |
| 11645 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11646 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11647 | {__LINE__, |
| 11648 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11649 | AUTH_NONE, |
| 11650 | OK, |
| 11651 | kServer, |
| 11652 | AUTH_SYNC, |
| 11653 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11654 | 2, |
| 11655 | kNoSSL, |
| 11656 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11657 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11658 | {__LINE__, |
| 11659 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11660 | AUTH_NONE, |
| 11661 | OK, |
| 11662 | kServer, |
| 11663 | AUTH_ASYNC, |
| 11664 | ERR_FAILED, |
| 11665 | 2, |
| 11666 | kNoSSL, |
| 11667 | {TestRound(kGet, kServerChallenge, OK), |
| 11668 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11669 | {__LINE__, |
| 11670 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11671 | AUTH_NONE, |
| 11672 | OK, |
| 11673 | kServer, |
| 11674 | AUTH_ASYNC, |
| 11675 | OK, |
| 11676 | 2, |
| 11677 | kNoSSL, |
| 11678 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11679 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11680 | {__LINE__, |
| 11681 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11682 | AUTH_NONE, |
| 11683 | OK, |
| 11684 | kServer, |
| 11685 | AUTH_ASYNC, |
| 11686 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11687 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11688 | kNoSSL, |
| 11689 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11690 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11691 | TestRound(kGet, kServerChallenge, OK), |
| 11692 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11693 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11694 | {__LINE__, |
| 11695 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11696 | AUTH_NONE, |
| 11697 | OK, |
| 11698 | kServer, |
| 11699 | AUTH_NONE, |
| 11700 | OK, |
| 11701 | 1, |
| 11702 | kNoSSL, |
| 11703 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11704 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11705 | {__LINE__, |
| 11706 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11707 | AUTH_NONE, |
| 11708 | OK, |
| 11709 | kServer, |
| 11710 | AUTH_SYNC, |
| 11711 | OK, |
| 11712 | 2, |
| 11713 | kNoSSL, |
| 11714 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11715 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11716 | {__LINE__, |
| 11717 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11718 | AUTH_NONE, |
| 11719 | OK, |
| 11720 | kServer, |
| 11721 | AUTH_SYNC, |
| 11722 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11723 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11724 | kNoSSL, |
| 11725 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11726 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11727 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11728 | {__LINE__, |
| 11729 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11730 | AUTH_NONE, |
| 11731 | OK, |
| 11732 | kServer, |
| 11733 | AUTH_ASYNC, |
| 11734 | OK, |
| 11735 | 2, |
| 11736 | kNoSSL, |
| 11737 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11738 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11739 | {__LINE__, |
| 11740 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11741 | AUTH_NONE, |
| 11742 | OK, |
| 11743 | kServer, |
| 11744 | AUTH_ASYNC, |
| 11745 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11746 | 2, |
| 11747 | kNoSSL, |
| 11748 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11749 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11750 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11751 | {__LINE__, |
| 11752 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11753 | AUTH_SYNC, |
| 11754 | OK, |
| 11755 | kServer, |
| 11756 | AUTH_NONE, |
| 11757 | OK, |
| 11758 | 2, |
| 11759 | kNoSSL, |
| 11760 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11761 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11762 | {__LINE__, |
| 11763 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11764 | AUTH_SYNC, |
| 11765 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11766 | kServer, |
| 11767 | AUTH_NONE, |
| 11768 | OK, |
| 11769 | 2, |
| 11770 | kNoSSL, |
| 11771 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11772 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11773 | {__LINE__, |
| 11774 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11775 | AUTH_ASYNC, |
| 11776 | OK, |
| 11777 | kServer, |
| 11778 | AUTH_NONE, |
| 11779 | OK, |
| 11780 | 2, |
| 11781 | kNoSSL, |
| 11782 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11783 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11784 | {__LINE__, |
| 11785 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11786 | AUTH_ASYNC, |
| 11787 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11788 | kServer, |
| 11789 | AUTH_NONE, |
| 11790 | OK, |
| 11791 | 2, |
| 11792 | kNoSSL, |
| 11793 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11794 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11795 | {__LINE__, |
| 11796 | kProxy, |
| 11797 | AUTH_ASYNC, |
| 11798 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11799 | kServer, |
| 11800 | AUTH_NONE, |
| 11801 | OK, |
| 11802 | 3, |
| 11803 | kNoSSL, |
| 11804 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11805 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11806 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11807 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11808 | {__LINE__, |
| 11809 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11810 | AUTH_SYNC, |
| 11811 | OK, |
| 11812 | kServer, |
| 11813 | AUTH_SYNC, |
| 11814 | OK, |
| 11815 | 3, |
| 11816 | kNoSSL, |
| 11817 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11818 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11819 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11820 | {__LINE__, |
| 11821 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11822 | AUTH_SYNC, |
| 11823 | OK, |
| 11824 | kServer, |
| 11825 | AUTH_SYNC, |
| 11826 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11827 | 3, |
| 11828 | kNoSSL, |
| 11829 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11830 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11831 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11832 | {__LINE__, |
| 11833 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11834 | AUTH_ASYNC, |
| 11835 | OK, |
| 11836 | kServer, |
| 11837 | AUTH_SYNC, |
| 11838 | OK, |
| 11839 | 3, |
| 11840 | kNoSSL, |
| 11841 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11842 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11843 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11844 | {__LINE__, |
| 11845 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11846 | AUTH_ASYNC, |
| 11847 | OK, |
| 11848 | kServer, |
| 11849 | AUTH_SYNC, |
| 11850 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11851 | 3, |
| 11852 | kNoSSL, |
| 11853 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11854 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11855 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11856 | {__LINE__, |
| 11857 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11858 | AUTH_SYNC, |
| 11859 | OK, |
| 11860 | kServer, |
| 11861 | AUTH_ASYNC, |
| 11862 | OK, |
| 11863 | 3, |
| 11864 | kNoSSL, |
| 11865 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11866 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11867 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11868 | {__LINE__, |
| 11869 | kProxy, |
| 11870 | AUTH_SYNC, |
| 11871 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11872 | kServer, |
| 11873 | AUTH_ASYNC, |
| 11874 | OK, |
| 11875 | 4, |
| 11876 | kNoSSL, |
| 11877 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11878 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11879 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11880 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11881 | {__LINE__, |
| 11882 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11883 | AUTH_SYNC, |
| 11884 | OK, |
| 11885 | kServer, |
| 11886 | AUTH_ASYNC, |
| 11887 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11888 | 3, |
| 11889 | kNoSSL, |
| 11890 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11891 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11892 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11893 | {__LINE__, |
| 11894 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11895 | AUTH_ASYNC, |
| 11896 | OK, |
| 11897 | kServer, |
| 11898 | AUTH_ASYNC, |
| 11899 | OK, |
| 11900 | 3, |
| 11901 | kNoSSL, |
| 11902 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11903 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11904 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11905 | {__LINE__, |
| 11906 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11907 | AUTH_ASYNC, |
| 11908 | OK, |
| 11909 | kServer, |
| 11910 | AUTH_ASYNC, |
| 11911 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11912 | 3, |
| 11913 | kNoSSL, |
| 11914 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11915 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11916 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11917 | {__LINE__, |
| 11918 | kProxy, |
| 11919 | AUTH_ASYNC, |
| 11920 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11921 | kServer, |
| 11922 | AUTH_ASYNC, |
| 11923 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11924 | 4, |
| 11925 | kNoSSL, |
| 11926 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11927 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11928 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11929 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11930 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11931 | {__LINE__, |
| 11932 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11933 | AUTH_NONE, |
| 11934 | OK, |
| 11935 | kSecureServer, |
| 11936 | AUTH_NONE, |
| 11937 | OK, |
| 11938 | 1, |
| 11939 | 0, |
| 11940 | {TestRound(kGet, kSuccess, OK)}}, |
| 11941 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11942 | {__LINE__, |
| 11943 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11944 | AUTH_NONE, |
| 11945 | OK, |
| 11946 | kSecureServer, |
| 11947 | AUTH_SYNC, |
| 11948 | OK, |
| 11949 | 2, |
| 11950 | 0, |
| 11951 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11952 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11953 | {__LINE__, |
| 11954 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11955 | AUTH_NONE, |
| 11956 | OK, |
| 11957 | kSecureServer, |
| 11958 | AUTH_SYNC, |
| 11959 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11960 | 2, |
| 11961 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11962 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11963 | {__LINE__, |
| 11964 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11965 | AUTH_NONE, |
| 11966 | OK, |
| 11967 | kSecureServer, |
| 11968 | AUTH_ASYNC, |
| 11969 | OK, |
| 11970 | 2, |
| 11971 | 0, |
| 11972 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11973 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11974 | {__LINE__, |
| 11975 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11976 | AUTH_NONE, |
| 11977 | OK, |
| 11978 | kSecureServer, |
| 11979 | AUTH_ASYNC, |
| 11980 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11981 | 2, |
| 11982 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11983 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11984 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11985 | {__LINE__, |
| 11986 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11987 | AUTH_NONE, |
| 11988 | OK, |
| 11989 | kSecureServer, |
| 11990 | AUTH_NONE, |
| 11991 | OK, |
| 11992 | 1, |
| 11993 | 0, |
| 11994 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11995 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11996 | {__LINE__, |
| 11997 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11998 | AUTH_NONE, |
| 11999 | OK, |
| 12000 | kSecureServer, |
| 12001 | AUTH_SYNC, |
| 12002 | OK, |
| 12003 | 2, |
| 12004 | 0, |
| 12005 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12006 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12007 | {__LINE__, |
| 12008 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12009 | AUTH_NONE, |
| 12010 | OK, |
| 12011 | kSecureServer, |
| 12012 | AUTH_SYNC, |
| 12013 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12014 | 2, |
| 12015 | 0, |
| 12016 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12017 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12018 | {__LINE__, |
| 12019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12020 | AUTH_NONE, |
| 12021 | OK, |
| 12022 | kSecureServer, |
| 12023 | AUTH_ASYNC, |
| 12024 | OK, |
| 12025 | 2, |
| 12026 | 0, |
| 12027 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12028 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12029 | {__LINE__, |
| 12030 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12031 | AUTH_NONE, |
| 12032 | OK, |
| 12033 | kSecureServer, |
| 12034 | AUTH_ASYNC, |
| 12035 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12036 | 2, |
| 12037 | 0, |
| 12038 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12039 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12040 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12041 | {__LINE__, |
| 12042 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12043 | AUTH_SYNC, |
| 12044 | OK, |
| 12045 | kSecureServer, |
| 12046 | AUTH_NONE, |
| 12047 | OK, |
| 12048 | 2, |
| 12049 | 1, |
| 12050 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12051 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12052 | {__LINE__, |
| 12053 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12054 | AUTH_SYNC, |
| 12055 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12056 | kSecureServer, |
| 12057 | AUTH_NONE, |
| 12058 | OK, |
| 12059 | 2, |
| 12060 | kNoSSL, |
| 12061 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12062 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12063 | {__LINE__, |
| 12064 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12065 | AUTH_SYNC, |
| 12066 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12067 | kSecureServer, |
| 12068 | AUTH_NONE, |
| 12069 | OK, |
| 12070 | 2, |
| 12071 | kNoSSL, |
| 12072 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12073 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12074 | {__LINE__, |
| 12075 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12076 | AUTH_SYNC, |
| 12077 | ERR_UNEXPECTED, |
| 12078 | kSecureServer, |
| 12079 | AUTH_NONE, |
| 12080 | OK, |
| 12081 | 2, |
| 12082 | kNoSSL, |
| 12083 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12084 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12085 | {__LINE__, |
| 12086 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12087 | AUTH_ASYNC, |
| 12088 | OK, |
| 12089 | kSecureServer, |
| 12090 | AUTH_NONE, |
| 12091 | OK, |
| 12092 | 2, |
| 12093 | 1, |
| 12094 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12095 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12096 | {__LINE__, |
| 12097 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12098 | AUTH_ASYNC, |
| 12099 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12100 | kSecureServer, |
| 12101 | AUTH_NONE, |
| 12102 | OK, |
| 12103 | 2, |
| 12104 | kNoSSL, |
| 12105 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12106 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12107 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12108 | {__LINE__, |
| 12109 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12110 | AUTH_SYNC, |
| 12111 | OK, |
| 12112 | kSecureServer, |
| 12113 | AUTH_SYNC, |
| 12114 | OK, |
| 12115 | 3, |
| 12116 | 1, |
| 12117 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12118 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12119 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12120 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12121 | {__LINE__, |
| 12122 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12123 | AUTH_SYNC, |
| 12124 | OK, |
| 12125 | kSecureServer, |
| 12126 | AUTH_SYNC, |
| 12127 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12128 | 3, |
| 12129 | 1, |
| 12130 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12131 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12132 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12133 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12134 | {__LINE__, |
| 12135 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12136 | AUTH_ASYNC, |
| 12137 | OK, |
| 12138 | kSecureServer, |
| 12139 | AUTH_SYNC, |
| 12140 | OK, |
| 12141 | 3, |
| 12142 | 1, |
| 12143 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12144 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12145 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12146 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12147 | {__LINE__, |
| 12148 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12149 | AUTH_ASYNC, |
| 12150 | OK, |
| 12151 | kSecureServer, |
| 12152 | AUTH_SYNC, |
| 12153 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12154 | 3, |
| 12155 | 1, |
| 12156 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12157 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12158 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12159 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12160 | {__LINE__, |
| 12161 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12162 | AUTH_SYNC, |
| 12163 | OK, |
| 12164 | kSecureServer, |
| 12165 | AUTH_ASYNC, |
| 12166 | OK, |
| 12167 | 3, |
| 12168 | 1, |
| 12169 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12170 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12171 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12172 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12173 | {__LINE__, |
| 12174 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12175 | AUTH_SYNC, |
| 12176 | OK, |
| 12177 | kSecureServer, |
| 12178 | AUTH_ASYNC, |
| 12179 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12180 | 3, |
| 12181 | 1, |
| 12182 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12183 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12184 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12185 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12186 | {__LINE__, |
| 12187 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12188 | AUTH_ASYNC, |
| 12189 | OK, |
| 12190 | kSecureServer, |
| 12191 | AUTH_ASYNC, |
| 12192 | OK, |
| 12193 | 3, |
| 12194 | 1, |
| 12195 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12196 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12197 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12198 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12199 | {__LINE__, |
| 12200 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12201 | AUTH_ASYNC, |
| 12202 | OK, |
| 12203 | kSecureServer, |
| 12204 | AUTH_ASYNC, |
| 12205 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12206 | 3, |
| 12207 | 1, |
| 12208 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12209 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12210 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12211 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12212 | {__LINE__, |
| 12213 | kProxy, |
| 12214 | AUTH_ASYNC, |
| 12215 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12216 | kSecureServer, |
| 12217 | AUTH_ASYNC, |
| 12218 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12219 | 4, |
| 12220 | 2, |
| 12221 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12222 | TestRound(kConnect, kProxyChallenge, OK), |
| 12223 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12224 | &kServerChallenge), |
| 12225 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12226 | }; |
| 12227 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12228 | for (const auto& test_config : test_configs) { |
| 12229 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12230 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12231 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12232 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12233 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12234 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12235 | |
| 12236 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12237 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12238 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12239 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12240 | std::string auth_challenge = "Mock realm=proxy"; |
| 12241 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12242 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12243 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12244 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12245 | empty_ssl_info, origin, |
| 12246 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12247 | auth_handler->SetGenerateExpectation( |
| 12248 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12249 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12250 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12251 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12252 | } |
| 12253 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12254 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12255 | std::string auth_challenge = "Mock realm=server"; |
| 12256 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12257 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12258 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12259 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12260 | empty_ssl_info, origin, |
| 12261 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12262 | auth_handler->SetGenerateExpectation( |
| 12263 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12264 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12265 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12266 | |
| 12267 | // The second handler always succeeds. It should only be used where there |
| 12268 | // are multiple auth sessions for server auth in the same network |
| 12269 | // transaction using the same auth scheme. |
| 12270 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12271 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12272 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12273 | empty_ssl_info, origin, |
| 12274 | NetLogWithSource()); |
| 12275 | second_handler->SetGenerateExpectation(true, OK); |
| 12276 | auth_factory->AddMockHandler(second_handler.release(), |
| 12277 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12278 | } |
| 12279 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12280 | session_deps_.proxy_service = |
| 12281 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12282 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12283 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12284 | } |
| 12285 | |
| 12286 | HttpRequestInfo request; |
| 12287 | request.method = "GET"; |
| 12288 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12289 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12291 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12292 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12293 | |
| 12294 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12295 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12296 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame^] | 12297 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12298 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12299 | |
| 12300 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12301 | mock_reads.back().push_back(read_write_round.read); |
| 12302 | mock_writes.back().push_back(read_write_round.write); |
| 12303 | |
| 12304 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12305 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12306 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12307 | mock_reads.push_back(std::vector<MockRead>()); |
| 12308 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12309 | } |
| 12310 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12311 | if (read_write_round.extra_read) { |
| 12312 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12313 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12314 | if (read_write_round.extra_write) { |
| 12315 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12316 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12317 | |
| 12318 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12319 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12320 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12321 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12322 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12324 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12325 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12326 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12327 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12328 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12329 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12330 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12331 | } |
| 12332 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12333 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12334 | // they are as well. |
| 12335 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12336 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12337 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame^] | 12338 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12339 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12340 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12341 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12342 | int rv; |
| 12343 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12344 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12345 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12346 | rv = trans.RestartWithAuth( |
| 12347 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12348 | } |
| 12349 | if (rv == ERR_IO_PENDING) |
| 12350 | rv = callback.WaitForResult(); |
| 12351 | |
| 12352 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12353 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12354 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12355 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12356 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12357 | continue; |
| 12358 | } |
| 12359 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12360 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12361 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12362 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12363 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12364 | } |
| 12365 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12366 | } |
| 12367 | } |
| 12368 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12369 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12370 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12371 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12372 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12373 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12374 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12375 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12376 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12377 | |
| 12378 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12379 | auth_handler->set_connection_based(true); |
| 12380 | std::string auth_challenge = "Mock realm=server"; |
| 12381 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12382 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12383 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12384 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12385 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12386 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12387 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12388 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12389 | int rv = OK; |
| 12390 | const HttpResponseInfo* response = NULL; |
| 12391 | HttpRequestInfo request; |
| 12392 | request.method = "GET"; |
| 12393 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12396 | |
| 12397 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12398 | // to validate that the TCP socket is not released to the pool between |
| 12399 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12400 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12401 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12402 | 50, // Max sockets for pool |
| 12403 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12404 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12405 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12406 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12407 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12408 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12409 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12412 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12413 | |
| 12414 | const MockWrite kGet( |
| 12415 | "GET / HTTP/1.1\r\n" |
| 12416 | "Host: www.example.com\r\n" |
| 12417 | "Connection: keep-alive\r\n\r\n"); |
| 12418 | const MockWrite kGetAuth( |
| 12419 | "GET / HTTP/1.1\r\n" |
| 12420 | "Host: www.example.com\r\n" |
| 12421 | "Connection: keep-alive\r\n" |
| 12422 | "Authorization: auth_token\r\n\r\n"); |
| 12423 | |
| 12424 | const MockRead kServerChallenge( |
| 12425 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12426 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12427 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12428 | "Content-Length: 14\r\n\r\n" |
| 12429 | "Unauthorized\r\n"); |
| 12430 | const MockRead kSuccess( |
| 12431 | "HTTP/1.1 200 OK\r\n" |
| 12432 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12433 | "Content-Length: 3\r\n\r\n" |
| 12434 | "Yes"); |
| 12435 | |
| 12436 | MockWrite writes[] = { |
| 12437 | // First round |
| 12438 | kGet, |
| 12439 | // Second round |
| 12440 | kGetAuth, |
| 12441 | // Third round |
| 12442 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12443 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12444 | kGetAuth, |
| 12445 | // Competing request |
| 12446 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12447 | }; |
| 12448 | MockRead reads[] = { |
| 12449 | // First round |
| 12450 | kServerChallenge, |
| 12451 | // Second round |
| 12452 | kServerChallenge, |
| 12453 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12454 | kServerChallenge, |
| 12455 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12456 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12457 | // Competing response |
| 12458 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12459 | }; |
| 12460 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12461 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12462 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12463 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12464 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12465 | |
| 12466 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12467 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12468 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12469 | if (rv == ERR_IO_PENDING) |
| 12470 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12471 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12472 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12473 | ASSERT_TRUE(response); |
| 12474 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12475 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12476 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12477 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12478 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12479 | // In between rounds, another request comes in for the same domain. |
| 12480 | // It should not be able to grab the TCP socket that trans has already |
| 12481 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12482 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12483 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12484 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12485 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12487 | // callback_compete.WaitForResult at this point would stall forever, |
| 12488 | // since the HttpNetworkTransaction does not release the request back to |
| 12489 | // the pool until after authentication completes. |
| 12490 | |
| 12491 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12492 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12493 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12494 | if (rv == ERR_IO_PENDING) |
| 12495 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12496 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12497 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12498 | ASSERT_TRUE(response); |
| 12499 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12500 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12501 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12502 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12503 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12504 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12505 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12506 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12507 | if (rv == ERR_IO_PENDING) |
| 12508 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12509 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12510 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12511 | ASSERT_TRUE(response); |
| 12512 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12513 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12514 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12515 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12516 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12517 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12518 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12519 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12520 | if (rv == ERR_IO_PENDING) |
| 12521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12522 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12523 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12524 | ASSERT_TRUE(response); |
| 12525 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12526 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12527 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12528 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12529 | // auth handler should transition to a DONE state in concert with the remote |
| 12530 | // server. But that's not something we can test here with a mock handler. |
| 12531 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12532 | auth_handler->state()); |
| 12533 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12534 | // Read the body since the fourth round was successful. This will also |
| 12535 | // release the socket back to the pool. |
| 12536 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12537 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12538 | if (rv == ERR_IO_PENDING) |
| 12539 | rv = callback.WaitForResult(); |
| 12540 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12541 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12542 | EXPECT_EQ(0, rv); |
| 12543 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12544 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12545 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12546 | |
| 12547 | // The competing request can now finish. Wait for the headers and then |
| 12548 | // read the body. |
| 12549 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12550 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12551 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12552 | if (rv == ERR_IO_PENDING) |
| 12553 | rv = callback.WaitForResult(); |
| 12554 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12555 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12556 | EXPECT_EQ(0, rv); |
| 12557 | |
| 12558 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12559 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12560 | } |
| 12561 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12562 | // This tests the case that a request is issued via http instead of spdy after |
| 12563 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12564 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12565 | HttpRequestInfo request; |
| 12566 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12567 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12568 | |
| 12569 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12570 | MockWrite( |
| 12571 | "GET / HTTP/1.1\r\n" |
| 12572 | "Host: www.example.org\r\n" |
| 12573 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12574 | }; |
| 12575 | |
| 12576 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12577 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12578 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12579 | MockRead("\r\n"), |
| 12580 | MockRead("hello world"), |
| 12581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12582 | }; |
| 12583 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12584 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12585 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12586 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12588 | |
| 12589 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12590 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12593 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12594 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12599 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12601 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12604 | ASSERT_TRUE(response); |
| 12605 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12606 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12607 | |
| 12608 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12609 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12610 | EXPECT_EQ("hello world", response_data); |
| 12611 | |
| 12612 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12613 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12614 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12615 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12616 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12617 | // immediate server closing of the socket. |
| 12618 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12619 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12620 | HttpRequestInfo request; |
| 12621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12622 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12623 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12624 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12625 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12627 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12628 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12629 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12630 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12631 | |
| 12632 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12633 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12634 | }; |
| 12635 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12636 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12637 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12638 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12640 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12645 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12647 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12648 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12649 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12650 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12651 | // it gets it. This is needed since the auth handler may get destroyed |
| 12652 | // before we get a chance to query it. |
| 12653 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12654 | public: |
| 12655 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12656 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12657 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12658 | |
| 12659 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12660 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12661 | const HttpRequestInfo* request, |
| 12662 | const CompletionCallback& callback, |
| 12663 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12664 | *url_ = request->url; |
| 12665 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12666 | credentials, request, callback, auth_token); |
| 12667 | } |
| 12668 | |
| 12669 | private: |
| 12670 | GURL* url_; |
| 12671 | }; |
| 12672 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12673 | // Test that if we cancel the transaction as the connection is completing, that |
| 12674 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12675 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12676 | // Setup everything about the connection to complete synchronously, so that |
| 12677 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12678 | // for is the callback from the HttpStreamRequest. |
| 12679 | // Then cancel the transaction. |
| 12680 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12681 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12682 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12683 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12684 | MockRead(SYNCHRONOUS, "hello world"), |
| 12685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12686 | }; |
| 12687 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12688 | HttpRequestInfo request; |
| 12689 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12690 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12691 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12692 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12693 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12694 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12696 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12698 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12701 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12702 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12703 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12704 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12706 | trans.reset(); // Cancel the transaction here. |
| 12707 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12708 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12709 | } |
| 12710 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12711 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12712 | // stream is drained properly and added back to the socket pool. The main |
| 12713 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12714 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12715 | // deleted. |
| 12716 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12717 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12718 | MockRead data_reads[] = { |
| 12719 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12720 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12721 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12722 | MockRead(ASYNC, "1"), |
| 12723 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12724 | // HttpNetworkTransaction has been deleted. |
| 12725 | MockRead(ASYNC, "2"), |
| 12726 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12727 | }; |
| 12728 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12732 | |
| 12733 | { |
| 12734 | HttpRequestInfo request; |
| 12735 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12736 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12737 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12739 | TestCompletionCallback callback; |
| 12740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12743 | callback.WaitForResult(); |
| 12744 | |
| 12745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12746 | ASSERT_TRUE(response); |
| 12747 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12748 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12749 | |
| 12750 | // The transaction and HttpRequestInfo are deleted. |
| 12751 | } |
| 12752 | |
| 12753 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12754 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12755 | |
| 12756 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12757 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12758 | } |
| 12759 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12760 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12761 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12762 | session_deps_.proxy_service = |
| 12763 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12764 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12765 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12767 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12768 | HttpRequestInfo request; |
| 12769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12770 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12771 | |
| 12772 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12773 | MockWrite( |
| 12774 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12775 | "Host: www.example.org\r\n" |
| 12776 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12777 | }; |
| 12778 | |
| 12779 | MockRead data_reads1[] = { |
| 12780 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12781 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12782 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12783 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12784 | }; |
| 12785 | |
| 12786 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12787 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12788 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12790 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12792 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12793 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12794 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12795 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12796 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12798 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12800 | |
| 12801 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12804 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12805 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12806 | |
| 12807 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12808 | EXPECT_EQ(200, response->headers->response_code()); |
| 12809 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12810 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12811 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12812 | HostPortPair::FromString("myproxy:70")), |
| 12813 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12814 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12815 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12816 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12817 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12818 | |
| 12819 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12820 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12821 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12822 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12823 | } |
| 12824 | |
| 12825 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12826 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12827 | session_deps_.proxy_service = |
| 12828 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12830 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12832 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12833 | HttpRequestInfo request; |
| 12834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12835 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12836 | |
| 12837 | // Since we have proxy, should try to establish tunnel. |
| 12838 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12839 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12840 | "Host: www.example.org:443\r\n" |
| 12841 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12842 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12843 | MockWrite("GET / HTTP/1.1\r\n" |
| 12844 | "Host: www.example.org\r\n" |
| 12845 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12846 | }; |
| 12847 | |
| 12848 | MockRead data_reads1[] = { |
| 12849 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12850 | |
| 12851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12852 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12853 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12854 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12855 | }; |
| 12856 | |
| 12857 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12858 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12859 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12860 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12863 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12866 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12867 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12868 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12869 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12871 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12873 | |
| 12874 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12875 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12876 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12877 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12878 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12879 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12880 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12881 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12882 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12883 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12884 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12886 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12887 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12888 | |
| 12889 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12890 | EXPECT_EQ(200, response->headers->response_code()); |
| 12891 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12892 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12893 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12894 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12895 | HostPortPair::FromString("myproxy:70")), |
| 12896 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12897 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12898 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12899 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12900 | |
| 12901 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12902 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12903 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12904 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12905 | } |
| 12906 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12907 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12908 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12909 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12910 | session_deps_.proxy_service = |
| 12911 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12912 | BoundTestNetLog log; |
| 12913 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12915 | |
| 12916 | HttpRequestInfo request; |
| 12917 | request.method = "GET"; |
| 12918 | request.url = GURL("https://[::1]:443/"); |
| 12919 | |
| 12920 | // Since we have proxy, should try to establish tunnel. |
| 12921 | MockWrite data_writes1[] = { |
| 12922 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12923 | "Host: [::1]:443\r\n" |
| 12924 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12925 | |
| 12926 | MockWrite("GET / HTTP/1.1\r\n" |
| 12927 | "Host: [::1]\r\n" |
| 12928 | "Connection: keep-alive\r\n\r\n"), |
| 12929 | }; |
| 12930 | |
| 12931 | MockRead data_reads1[] = { |
| 12932 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12933 | |
| 12934 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12935 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12936 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12937 | MockRead(SYNCHRONOUS, OK), |
| 12938 | }; |
| 12939 | |
| 12940 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12941 | data_writes1, arraysize(data_writes1)); |
| 12942 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12943 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12945 | |
| 12946 | TestCompletionCallback callback1; |
| 12947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12948 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12950 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12952 | |
| 12953 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12954 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12955 | TestNetLogEntry::List entries; |
| 12956 | log.GetEntries(&entries); |
| 12957 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12958 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12959 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12960 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12961 | entries, pos, |
| 12962 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12963 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12964 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12965 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12966 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12967 | |
| 12968 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12969 | EXPECT_EQ(200, response->headers->response_code()); |
| 12970 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12971 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12972 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12973 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12974 | HostPortPair::FromString("myproxy:70")), |
| 12975 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12976 | |
| 12977 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12978 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12979 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12980 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12981 | } |
| 12982 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12983 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12984 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12985 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12986 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12987 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12988 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12989 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12990 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12991 | HttpRequestInfo request; |
| 12992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12993 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12994 | |
| 12995 | // Since we have proxy, should try to establish tunnel. |
| 12996 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12997 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12998 | "Host: www.example.org:443\r\n" |
| 12999 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13000 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13001 | MockWrite("GET / HTTP/1.1\r\n" |
| 13002 | "Host: www.example.org\r\n" |
| 13003 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13004 | }; |
| 13005 | |
| 13006 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13007 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13008 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13009 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13010 | }; |
| 13011 | |
| 13012 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13013 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13014 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13015 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13017 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13018 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13020 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13022 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13024 | |
| 13025 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13026 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13027 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13028 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13029 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13030 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13031 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13032 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13033 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13034 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13035 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13036 | } |
| 13037 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13038 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13039 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13040 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13041 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13042 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13043 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13044 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13045 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13046 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13047 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13048 | }; |
| 13049 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13050 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13051 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13052 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13053 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13054 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13055 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13058 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13059 | |
| 13060 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13061 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13062 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13063 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13064 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13065 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13066 | |
| 13067 | HttpRequestInfo request; |
| 13068 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13069 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13070 | |
| 13071 | // This is the important line that marks this as a preconnect. |
| 13072 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13075 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13076 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13077 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13078 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13079 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13080 | } |
| 13081 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13082 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13083 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13084 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13085 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13086 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13087 | request_info.url = GURL("https://www.example.com/"); |
| 13088 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13089 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13090 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13091 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13092 | MockWrite data_writes[] = { |
| 13093 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13094 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13095 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13102 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13103 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13104 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13105 | rv = callback.WaitForResult(); |
| 13106 | ASSERT_EQ(error, rv); |
| 13107 | } |
| 13108 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13109 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13110 | // Just check a grab bag of cert errors. |
| 13111 | static const int kErrors[] = { |
| 13112 | ERR_CERT_COMMON_NAME_INVALID, |
| 13113 | ERR_CERT_AUTHORITY_INVALID, |
| 13114 | ERR_CERT_DATE_INVALID, |
| 13115 | }; |
| 13116 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13117 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13118 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13119 | } |
| 13120 | } |
| 13121 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13122 | // Ensure that a client certificate is removed from the SSL client auth |
| 13123 | // cache when: |
| 13124 | // 1) No proxy is involved. |
| 13125 | // 2) TLS False Start is disabled. |
| 13126 | // 3) The initial TLS handshake requests a client certificate. |
| 13127 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13128 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13129 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13130 | request_info.url = GURL("https://www.example.com/"); |
| 13131 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13132 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13133 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13134 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13135 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13136 | |
| 13137 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13138 | // CertificateRequest is received for the first time, the handshake will |
| 13139 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13140 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13141 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13143 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13144 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13145 | |
| 13146 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13147 | // False Start is not being used, the result of the SSL handshake will be |
| 13148 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13149 | // matches the result of a server sending a handshake_failure alert, |
| 13150 | // rather than a Finished message, because it requires a client |
| 13151 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13152 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13153 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13155 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13156 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13157 | |
| 13158 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13159 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13160 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13161 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13162 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13163 | // requiring a client certificate, this fallback handshake should also |
| 13164 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13165 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13166 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13168 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13169 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13170 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13171 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13172 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13173 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13174 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13175 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13176 | // requiring a client certificate, this fallback handshake should also |
| 13177 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13178 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13179 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13180 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13181 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13182 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13183 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13184 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13185 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13186 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13187 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13188 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13189 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13190 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13191 | |
| 13192 | // Complete the SSL handshake, which should abort due to requiring a |
| 13193 | // client certificate. |
| 13194 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13195 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13196 | |
| 13197 | // Indicate that no certificate should be supplied. From the perspective |
| 13198 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13199 | // certificate, so this is the same as supply a |
| 13200 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13201 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13202 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13203 | |
| 13204 | // Ensure the certificate was added to the client auth cache before |
| 13205 | // allowing the connection to continue restarting. |
| 13206 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13207 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13208 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13209 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13210 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13211 | |
| 13212 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13213 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13214 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13215 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13216 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13217 | |
| 13218 | // Ensure that the client certificate is removed from the cache on a |
| 13219 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13220 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13221 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13222 | } |
| 13223 | |
| 13224 | // Ensure that a client certificate is removed from the SSL client auth |
| 13225 | // cache when: |
| 13226 | // 1) No proxy is involved. |
| 13227 | // 2) TLS False Start is enabled. |
| 13228 | // 3) The initial TLS handshake requests a client certificate. |
| 13229 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13230 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13231 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13232 | request_info.url = GURL("https://www.example.com/"); |
| 13233 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13234 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13235 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13236 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13237 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13238 | |
| 13239 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13240 | // return successfully after reading up to the peer's Certificate message. |
| 13241 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13242 | // enqueue application data to be sent in the same packet as the |
| 13243 | // ChangeCipherSpec and Finished messages. |
| 13244 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13245 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13246 | // Finished messages. If there was an error negotiating with the peer, |
| 13247 | // such as due to the peer requiring a client certificate when none was |
| 13248 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13249 | // called. |
| 13250 | |
| 13251 | // Like the non-False Start case, when a client certificate is requested by |
| 13252 | // the peer, the handshake is aborted during the Connect() call. |
| 13253 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13254 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13255 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13257 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13259 | |
| 13260 | // When a client certificate is supplied, Connect() will not be aborted |
| 13261 | // when the peer requests the certificate. Instead, the handshake will |
| 13262 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13263 | // the socket. The handshake messages are not processed until Read() is |
| 13264 | // called, which then detects that the handshake was aborted, due to the |
| 13265 | // peer sending a handshake_failure because it requires a client |
| 13266 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13267 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13268 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13270 | MockRead data2_reads[] = { |
| 13271 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13272 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13273 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13274 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13275 | |
| 13276 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13277 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13278 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13279 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13280 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13282 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13283 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13284 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13285 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13286 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13287 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13288 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13290 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13291 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13292 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13293 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13294 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13295 | ssl_data5.cert_request_info = cert_request.get(); |
| 13296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13297 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13298 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13299 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13301 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13302 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13303 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13304 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13305 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13306 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13307 | |
| 13308 | // Complete the SSL handshake, which should abort due to requiring a |
| 13309 | // client certificate. |
| 13310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13311 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13312 | |
| 13313 | // Indicate that no certificate should be supplied. From the perspective |
| 13314 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13315 | // certificate, so this is the same as supply a |
| 13316 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13317 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13318 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13319 | |
| 13320 | // Ensure the certificate was added to the client auth cache before |
| 13321 | // allowing the connection to continue restarting. |
| 13322 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13323 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13324 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13325 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13326 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13327 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13328 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13329 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13330 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13331 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13332 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13333 | |
| 13334 | // Ensure that the client certificate is removed from the cache on a |
| 13335 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13336 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13337 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13338 | } |
| 13339 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13340 | // Ensure that a client certificate is removed from the SSL client auth |
| 13341 | // cache when: |
| 13342 | // 1) An HTTPS proxy is involved. |
| 13343 | // 3) The HTTPS proxy requests a client certificate. |
| 13344 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13345 | // proxy. |
| 13346 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13347 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13348 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13349 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13350 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13351 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13352 | |
| 13353 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13354 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13355 | |
| 13356 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13357 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13358 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13359 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13360 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13361 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13363 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13364 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13365 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13366 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13367 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13369 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13370 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13371 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13372 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13373 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13374 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13375 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13377 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13378 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13379 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13380 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13381 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13382 | requests[0].url = GURL("https://www.example.com/"); |
| 13383 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13384 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13385 | |
| 13386 | requests[1].url = GURL("http://www.example.com/"); |
| 13387 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13388 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13389 | |
| 13390 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13391 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13394 | |
| 13395 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13396 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13397 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13398 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13399 | |
| 13400 | // Complete the SSL handshake, which should abort due to requiring a |
| 13401 | // client certificate. |
| 13402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13403 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13404 | |
| 13405 | // Indicate that no certificate should be supplied. From the perspective |
| 13406 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13407 | // certificate, so this is the same as supply a |
| 13408 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13409 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13410 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13411 | |
| 13412 | // Ensure the certificate was added to the client auth cache before |
| 13413 | // allowing the connection to continue restarting. |
| 13414 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13415 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13416 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13417 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13418 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13419 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13420 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13421 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13422 | HostPortPair("www.example.com", 443), &client_cert, |
| 13423 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13424 | |
| 13425 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13426 | // then consume ssl_data3, which should also fail. The result code is |
| 13427 | // checked against what ssl_data3 should return. |
| 13428 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13429 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13430 | |
| 13431 | // Now that the new handshake has failed, ensure that the client |
| 13432 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13433 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13434 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13435 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13436 | HostPortPair("www.example.com", 443), &client_cert, |
| 13437 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13438 | } |
| 13439 | } |
| 13440 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13441 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13442 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13443 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13444 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13445 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13446 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13447 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13448 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13449 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13450 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13451 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13452 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13453 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13454 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13455 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13456 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13457 | SpdySerializedFrame host1_resp_body( |
| 13458 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13459 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13460 | SpdySerializedFrame host2_resp_body( |
| 13461 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13462 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13463 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13464 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13465 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13466 | }; |
| 13467 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13468 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13469 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13470 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13471 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13472 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13473 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13474 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13475 | HttpRequestInfo request1; |
| 13476 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13477 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13478 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13479 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13480 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13481 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13483 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13484 | |
| 13485 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13486 | ASSERT_TRUE(response); |
| 13487 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13488 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13489 | |
| 13490 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13491 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13492 | EXPECT_EQ("hello!", response_data); |
| 13493 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13494 | // Preload mail.example.com into HostCache. |
| 13495 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13496 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13497 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13498 | std::unique_ptr<HostResolver::Request> request; |
| 13499 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13500 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13501 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13503 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13504 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13505 | |
| 13506 | HttpRequestInfo request2; |
| 13507 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13508 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13509 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13510 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13512 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13514 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13515 | |
| 13516 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13517 | ASSERT_TRUE(response); |
| 13518 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13519 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13520 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13521 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13522 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13523 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13524 | } |
| 13525 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13526 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13527 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13528 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13530 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13531 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13532 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13533 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13534 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13535 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13536 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13537 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13538 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13539 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13540 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13541 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13542 | SpdySerializedFrame host1_resp_body( |
| 13543 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13544 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13545 | SpdySerializedFrame host2_resp_body( |
| 13546 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13547 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13548 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13549 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13550 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13551 | }; |
| 13552 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13553 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13554 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13555 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13556 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13557 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13558 | |
| 13559 | TestCompletionCallback callback; |
| 13560 | HttpRequestInfo request1; |
| 13561 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13562 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13563 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13564 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13566 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13568 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13569 | |
| 13570 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13571 | ASSERT_TRUE(response); |
| 13572 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13573 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13574 | |
| 13575 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13576 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13577 | EXPECT_EQ("hello!", response_data); |
| 13578 | |
| 13579 | HttpRequestInfo request2; |
| 13580 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13581 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13582 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13583 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13585 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13587 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13588 | |
| 13589 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13590 | ASSERT_TRUE(response); |
| 13591 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13592 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13593 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13594 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13595 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13596 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13597 | } |
| 13598 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13599 | // Regression test for https://crbug.com/546991. |
| 13600 | // The server might not be able to serve an IP pooled request, and might send a |
| 13601 | // 421 Misdirected Request response status to indicate this. |
| 13602 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13603 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13604 | // Two hosts resolve to the same IP address. |
| 13605 | const std::string ip_addr = "1.2.3.4"; |
| 13606 | IPAddress ip; |
| 13607 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13608 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13609 | |
| 13610 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 13611 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13612 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13613 | |
| 13614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13615 | |
| 13616 | // Two requests on the first connection. |
| 13617 | SpdySerializedFrame req1( |
| 13618 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13619 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13620 | SpdySerializedFrame req2( |
| 13621 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13622 | SpdySerializedFrame rst( |
| 13623 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13624 | MockWrite writes1[] = { |
| 13625 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13626 | CreateMockWrite(rst, 6), |
| 13627 | }; |
| 13628 | |
| 13629 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13630 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13631 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13632 | SpdyHeaderBlock response_headers; |
| 13633 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13634 | SpdySerializedFrame resp2( |
| 13635 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13636 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13637 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13638 | |
| 13639 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13640 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13641 | arraysize(writes1)); |
| 13642 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13643 | |
| 13644 | AddSSLSocketData(); |
| 13645 | |
| 13646 | // Retry the second request on a second connection. |
| 13647 | SpdyTestUtil spdy_util2; |
| 13648 | SpdySerializedFrame req3( |
| 13649 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13650 | MockWrite writes2[] = { |
| 13651 | CreateMockWrite(req3, 0), |
| 13652 | }; |
| 13653 | |
| 13654 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13655 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13656 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13657 | MockRead(ASYNC, 0, 3)}; |
| 13658 | |
| 13659 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13660 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13661 | arraysize(writes2)); |
| 13662 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13663 | |
| 13664 | AddSSLSocketData(); |
| 13665 | |
| 13666 | // Preload mail.example.org into HostCache. |
| 13667 | HostPortPair host_port("mail.example.org", 443); |
| 13668 | HostResolver::RequestInfo resolve_info(host_port); |
| 13669 | AddressList ignored; |
| 13670 | std::unique_ptr<HostResolver::Request> request; |
| 13671 | TestCompletionCallback callback; |
| 13672 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13673 | &ignored, callback.callback(), |
| 13674 | &request, NetLogWithSource()); |
| 13675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13676 | rv = callback.WaitForResult(); |
| 13677 | EXPECT_THAT(rv, IsOk()); |
| 13678 | |
| 13679 | HttpRequestInfo request1; |
| 13680 | request1.method = "GET"; |
| 13681 | request1.url = GURL("https://www.example.org/"); |
| 13682 | request1.load_flags = 0; |
| 13683 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13684 | |
| 13685 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13687 | rv = callback.WaitForResult(); |
| 13688 | EXPECT_THAT(rv, IsOk()); |
| 13689 | |
| 13690 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13691 | ASSERT_TRUE(response); |
| 13692 | ASSERT_TRUE(response->headers); |
| 13693 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13694 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13695 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13696 | std::string response_data; |
| 13697 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13698 | EXPECT_EQ("hello!", response_data); |
| 13699 | |
| 13700 | HttpRequestInfo request2; |
| 13701 | request2.method = "GET"; |
| 13702 | request2.url = GURL("https://mail.example.org/"); |
| 13703 | request2.load_flags = 0; |
| 13704 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13705 | |
| 13706 | BoundTestNetLog log; |
| 13707 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13709 | rv = callback.WaitForResult(); |
| 13710 | EXPECT_THAT(rv, IsOk()); |
| 13711 | |
| 13712 | response = trans2.GetResponseInfo(); |
| 13713 | ASSERT_TRUE(response); |
| 13714 | ASSERT_TRUE(response->headers); |
| 13715 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13716 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13717 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13718 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13719 | EXPECT_EQ("hello!", response_data); |
| 13720 | |
| 13721 | TestNetLogEntry::List entries; |
| 13722 | log.GetEntries(&entries); |
| 13723 | size_t pos = ExpectLogContainsSomewhere( |
| 13724 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, |
| 13725 | NetLogEventPhase::NONE); |
| 13726 | EXPECT_TRUE(entries[pos].GetIntegerValue("net_error", &rv)); |
| 13727 | EXPECT_THAT(rv, IsError(ERR_MISDIRECTED_REQUEST)); |
| 13728 | } |
| 13729 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13730 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13731 | public: |
| 13732 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13733 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13734 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13735 | |
| 13736 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13737 | |
| 13738 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13739 | int Resolve(const RequestInfo& info, |
| 13740 | RequestPriority priority, |
| 13741 | AddressList* addresses, |
| 13742 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13743 | std::unique_ptr<Request>* out_req, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13744 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13745 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13746 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13747 | } |
| 13748 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13749 | int ResolveFromCache(const RequestInfo& info, |
| 13750 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13751 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13752 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13753 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13754 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13755 | return rv; |
| 13756 | } |
| 13757 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13758 | MockCachingHostResolver* GetMockHostResolver() { |
| 13759 | return &host_resolver_; |
| 13760 | } |
| 13761 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13762 | private: |
| 13763 | MockCachingHostResolver host_resolver_; |
| 13764 | const HostPortPair host_port_; |
| 13765 | }; |
| 13766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13767 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13768 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13769 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13770 | OneTimeCachingHostResolver host_resolver( |
| 13771 | HostPortPair("mail.example.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13772 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13773 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13774 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13776 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13777 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13778 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13779 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13780 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13781 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13782 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13783 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13784 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13785 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13786 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13787 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13788 | SpdySerializedFrame host1_resp_body( |
| 13789 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13790 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13791 | SpdySerializedFrame host2_resp_body( |
| 13792 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13793 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13794 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13795 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13796 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13797 | }; |
| 13798 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13799 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13800 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13801 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13802 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13803 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13804 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13805 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13806 | HttpRequestInfo request1; |
| 13807 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13808 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13809 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13810 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13812 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13814 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13815 | |
| 13816 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13817 | ASSERT_TRUE(response); |
| 13818 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13819 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13820 | |
| 13821 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13822 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13823 | EXPECT_EQ("hello!", response_data); |
| 13824 | |
| 13825 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13826 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13827 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13828 | std::unique_ptr<HostResolver::Request> request; |
| 13829 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13830 | callback.callback(), &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13832 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13833 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13834 | |
| 13835 | HttpRequestInfo request2; |
| 13836 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13837 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13838 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13839 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13840 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13841 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13843 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13844 | |
| 13845 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13846 | ASSERT_TRUE(response); |
| 13847 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13848 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13849 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13850 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13851 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13852 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13853 | } |
| 13854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13855 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13856 | const std::string https_url = "https://www.example.org:8080/"; |
| 13857 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13858 | |
| 13859 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13860 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13861 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13862 | |
| 13863 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13864 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13865 | }; |
| 13866 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13867 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13868 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13869 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13870 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13871 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13872 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13873 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13874 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13875 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13876 | |
| 13877 | // HTTP GET for the HTTP URL |
| 13878 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13879 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13880 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13881 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13882 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13883 | }; |
| 13884 | |
| 13885 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13886 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13887 | MockRead(ASYNC, 2, "hello"), |
| 13888 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13889 | }; |
| 13890 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13891 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13892 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13893 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13894 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13895 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13897 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13898 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13899 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13901 | |
| 13902 | // Start the first transaction to set up the SpdySession |
| 13903 | HttpRequestInfo request1; |
| 13904 | request1.method = "GET"; |
| 13905 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13906 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13907 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13908 | TestCompletionCallback callback1; |
| 13909 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13910 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13911 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13912 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13913 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13914 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13915 | |
| 13916 | // Now, start the HTTP request |
| 13917 | HttpRequestInfo request2; |
| 13918 | request2.method = "GET"; |
| 13919 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13920 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13921 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13922 | TestCompletionCallback callback2; |
| 13923 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13924 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13925 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13926 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13927 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13928 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13929 | } |
| 13930 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13931 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13932 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13933 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13934 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13935 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13936 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13937 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13938 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13939 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13941 | |
| 13942 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13943 | // negotiated. |
| 13944 | StaticSocketDataProvider data; |
| 13945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13946 | |
| 13947 | // 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] | 13948 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13949 | // mocked. This way the request relies on the alternate Job. |
| 13950 | StaticSocketDataProvider data_refused; |
| 13951 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13952 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13953 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13954 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13956 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13957 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13958 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13959 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13960 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13961 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13962 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13963 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13964 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13965 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13966 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13967 | TestCompletionCallback callback; |
| 13968 | |
| 13969 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13970 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13971 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13972 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13973 | } |
| 13974 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13975 | // 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] | 13976 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13977 | // succeeds, the request should succeed, even if the latter fails because |
| 13978 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13979 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13980 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13981 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13982 | |
| 13983 | // Negotiate HTTP/1.1 with alternative. |
| 13984 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13985 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13987 | |
| 13988 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13989 | // negotiated. |
| 13990 | StaticSocketDataProvider data; |
| 13991 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13992 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13993 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13994 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13995 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13997 | |
| 13998 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13999 | MockWrite("GET / HTTP/1.1\r\n" |
| 14000 | "Host: www.example.org\r\n" |
| 14001 | "Connection: keep-alive\r\n\r\n"), |
| 14002 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14003 | "Host: www.example.org\r\n" |
| 14004 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14005 | }; |
| 14006 | |
| 14007 | MockRead http_reads[] = { |
| 14008 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14009 | MockRead("Content-Type: text/html\r\n"), |
| 14010 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14011 | MockRead("foobar"), |
| 14012 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14013 | MockRead("Content-Type: text/html\r\n"), |
| 14014 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14015 | MockRead("another"), |
| 14016 | }; |
| 14017 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14018 | http_writes, arraysize(http_writes)); |
| 14019 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14020 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14021 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14023 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14024 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14025 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14026 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14027 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14028 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14029 | |
| 14030 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14031 | HttpRequestInfo request1; |
| 14032 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14033 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14034 | request1.load_flags = 0; |
| 14035 | TestCompletionCallback callback1; |
| 14036 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14037 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14038 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14039 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14040 | |
| 14041 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14042 | ASSERT_TRUE(response1); |
| 14043 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14044 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14045 | |
| 14046 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14047 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14048 | EXPECT_EQ("foobar", response_data1); |
| 14049 | |
| 14050 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14051 | // for alternative service. |
| 14052 | EXPECT_TRUE( |
| 14053 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14054 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14055 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14056 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14057 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14058 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14059 | HttpRequestInfo request2; |
| 14060 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14061 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14062 | request2.load_flags = 0; |
| 14063 | TestCompletionCallback callback2; |
| 14064 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14065 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14066 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14067 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14068 | |
| 14069 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14070 | ASSERT_TRUE(response2); |
| 14071 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14072 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14073 | |
| 14074 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14075 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14076 | EXPECT_EQ("another", response_data2); |
| 14077 | } |
| 14078 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14079 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14080 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14081 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14082 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14083 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14084 | HostPortPair alternative("alternative.example.org", 443); |
| 14085 | std::string origin_url = "https://origin.example.org:443"; |
| 14086 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14087 | |
| 14088 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14089 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14090 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14092 | |
| 14093 | // HTTP/1.1 data for |request1| and |request2|. |
| 14094 | MockWrite http_writes[] = { |
| 14095 | MockWrite( |
| 14096 | "GET / HTTP/1.1\r\n" |
| 14097 | "Host: alternative.example.org\r\n" |
| 14098 | "Connection: keep-alive\r\n\r\n"), |
| 14099 | MockWrite( |
| 14100 | "GET / HTTP/1.1\r\n" |
| 14101 | "Host: alternative.example.org\r\n" |
| 14102 | "Connection: keep-alive\r\n\r\n"), |
| 14103 | }; |
| 14104 | |
| 14105 | MockRead http_reads[] = { |
| 14106 | MockRead( |
| 14107 | "HTTP/1.1 200 OK\r\n" |
| 14108 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14109 | "Content-Length: 40\r\n\r\n" |
| 14110 | "first HTTP/1.1 response from alternative"), |
| 14111 | MockRead( |
| 14112 | "HTTP/1.1 200 OK\r\n" |
| 14113 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14114 | "Content-Length: 41\r\n\r\n" |
| 14115 | "second HTTP/1.1 response from alternative"), |
| 14116 | }; |
| 14117 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14118 | http_writes, arraysize(http_writes)); |
| 14119 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14120 | |
| 14121 | // This test documents that an alternate Job should not pool to an already |
| 14122 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14123 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14124 | StaticSocketDataProvider data_refused; |
| 14125 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14126 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14127 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14128 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14130 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14131 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14132 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14133 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14134 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14135 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14136 | |
| 14137 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14138 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14139 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14140 | request1.method = "GET"; |
| 14141 | request1.url = GURL(alternative_url); |
| 14142 | request1.load_flags = 0; |
| 14143 | TestCompletionCallback callback1; |
| 14144 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14145 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14146 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14147 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14148 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14149 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14150 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14151 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14152 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14153 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14154 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14155 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14156 | |
| 14157 | // Request for origin.example.org, which has an alternative service. This |
| 14158 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14159 | // 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] | 14160 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14161 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14162 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14163 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14164 | request2.method = "GET"; |
| 14165 | request2.url = GURL(origin_url); |
| 14166 | request2.load_flags = 0; |
| 14167 | TestCompletionCallback callback2; |
| 14168 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14169 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14170 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14171 | |
| 14172 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14173 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14174 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14175 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14176 | request3.method = "GET"; |
| 14177 | request3.url = GURL(alternative_url); |
| 14178 | request3.load_flags = 0; |
| 14179 | TestCompletionCallback callback3; |
| 14180 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14181 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14182 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14183 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14184 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14185 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14186 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14187 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14188 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14189 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14190 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14191 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14192 | } |
| 14193 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14194 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14195 | const std::string https_url = "https://www.example.org:8080/"; |
| 14196 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14197 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14198 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14199 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14200 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14201 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14202 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14203 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14204 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14205 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14206 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14207 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14208 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14209 | |
| 14210 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14211 | SpdyHeaderBlock req2_block; |
| 14212 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14213 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14214 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14215 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14216 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14217 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14218 | |
| 14219 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14220 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14221 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14222 | }; |
| 14223 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14224 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14225 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14226 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14227 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14228 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14229 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14230 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14231 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14232 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14233 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14234 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14235 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14236 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14237 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14238 | CreateMockRead(wrapped_resp1, 4), |
| 14239 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14240 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14241 | CreateMockRead(resp2, 8), |
| 14242 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14243 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14244 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14245 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14246 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14247 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14248 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14249 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14250 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14251 | session_deps_.proxy_service = |
| 14252 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14253 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14254 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14255 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14256 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14258 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14259 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14263 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14264 | |
| 14265 | // Start the first transaction to set up the SpdySession |
| 14266 | HttpRequestInfo request1; |
| 14267 | request1.method = "GET"; |
| 14268 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14269 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14270 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14271 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14272 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14273 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14274 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14275 | data1.RunUntilPaused(); |
| 14276 | base::RunLoop().RunUntilIdle(); |
| 14277 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14278 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14279 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14280 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14281 | LoadTimingInfo load_timing_info1; |
| 14282 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14283 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14284 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14285 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14286 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14287 | HttpRequestInfo request2; |
| 14288 | request2.method = "GET"; |
| 14289 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14290 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14291 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14292 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14293 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14294 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14295 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14296 | data1.RunUntilPaused(); |
| 14297 | base::RunLoop().RunUntilIdle(); |
| 14298 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14299 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14300 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14301 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14302 | |
| 14303 | LoadTimingInfo load_timing_info2; |
| 14304 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14305 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14306 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14307 | // HTTP requests over a SPDY session should have a different connection |
| 14308 | // socket_log_id than requests over a tunnel. |
| 14309 | 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] | 14310 | } |
| 14311 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14312 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14313 | // that we do not pool other origins that resolve to the same IP when |
| 14314 | // the certificate does not match the new origin. |
| 14315 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14316 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14317 | const std::string url1 = "http://www.example.org/"; |
| 14318 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14319 | const std::string ip_addr = "1.2.3.4"; |
| 14320 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14321 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14322 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14323 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14324 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14325 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14326 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14327 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14328 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14329 | |
| 14330 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14331 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14332 | }; |
| 14333 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14334 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14335 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14336 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14337 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14338 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14339 | }; |
| 14340 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14341 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14342 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14343 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14344 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14345 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14346 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14347 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14348 | |
| 14349 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14350 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14351 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14352 | |
| 14353 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14354 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14355 | }; |
| 14356 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14357 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14358 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14359 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14360 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14361 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14362 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14363 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14364 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14365 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14366 | |
| 14367 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14368 | // all others direct. |
| 14369 | ProxyConfig proxy_config; |
| 14370 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14371 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14372 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 14373 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14374 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14375 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14376 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14377 | // Load a valid cert. Note, that this does not need to |
| 14378 | // be valid for proxy because the MockSSLClientSocket does |
| 14379 | // not actually verify it. But SpdySession will use this |
| 14380 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14381 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14382 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14385 | |
| 14386 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14387 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14389 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14390 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14391 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14392 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14393 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14395 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14396 | |
| 14397 | // Start the first transaction to set up the SpdySession |
| 14398 | HttpRequestInfo request1; |
| 14399 | request1.method = "GET"; |
| 14400 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14401 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14402 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14403 | TestCompletionCallback callback1; |
| 14404 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14405 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14406 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14407 | data1.RunUntilPaused(); |
| 14408 | base::RunLoop().RunUntilIdle(); |
| 14409 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14410 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14411 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14412 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14413 | |
| 14414 | // Now, start the HTTP request |
| 14415 | HttpRequestInfo request2; |
| 14416 | request2.method = "GET"; |
| 14417 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14418 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14419 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14420 | TestCompletionCallback callback2; |
| 14421 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14422 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14423 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14424 | |
| 14425 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14426 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14427 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14428 | } |
| 14429 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14430 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14431 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14432 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14433 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14434 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14435 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14436 | |
| 14437 | MockRead reads1[] = { |
| 14438 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14439 | }; |
| 14440 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14441 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14442 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14443 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14444 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14445 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14446 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14447 | }; |
| 14448 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14449 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14450 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14451 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14452 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14453 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14454 | }; |
| 14455 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14456 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14457 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14458 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14459 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14460 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14462 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14463 | |
| 14464 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14465 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14467 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14468 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14469 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14470 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14471 | |
| 14472 | // Start the first transaction to set up the SpdySession and verify that |
| 14473 | // connection was closed. |
| 14474 | HttpRequestInfo request1; |
| 14475 | request1.method = "GET"; |
| 14476 | request1.url = GURL(https_url); |
| 14477 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14478 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14479 | TestCompletionCallback callback1; |
| 14480 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14481 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14482 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14483 | |
| 14484 | // Now, start the second request and make sure it succeeds. |
| 14485 | HttpRequestInfo request2; |
| 14486 | request2.method = "GET"; |
| 14487 | request2.url = GURL(https_url); |
| 14488 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14489 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14490 | TestCompletionCallback callback2; |
| 14491 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14492 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14493 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14494 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14495 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14496 | } |
| 14497 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14498 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14499 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14500 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14501 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14502 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14503 | |
| 14504 | // Use two different hosts with different IPs so they don't get pooled. |
| 14505 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14506 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14508 | |
| 14509 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14510 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14511 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14512 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14515 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14516 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14517 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14518 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14519 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14520 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14521 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14522 | SpdySerializedFrame host1_resp_body( |
| 14523 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14524 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14525 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14526 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14527 | }; |
| 14528 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14529 | // Use a separate test instance for the separate SpdySession that will be |
| 14530 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14531 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14532 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14533 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14534 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14535 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14536 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14537 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14538 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14539 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14540 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14541 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14542 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14543 | SpdySerializedFrame host2_resp_body( |
| 14544 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14545 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14546 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14547 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14548 | }; |
| 14549 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14550 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14551 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14552 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14553 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14554 | |
| 14555 | MockWrite http_write[] = { |
| 14556 | MockWrite("GET / HTTP/1.1\r\n" |
| 14557 | "Host: www.a.com\r\n" |
| 14558 | "Connection: keep-alive\r\n\r\n"), |
| 14559 | }; |
| 14560 | |
| 14561 | MockRead http_read[] = { |
| 14562 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14563 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14564 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14565 | MockRead("hello!"), |
| 14566 | }; |
| 14567 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14568 | http_write, arraysize(http_write)); |
| 14569 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14570 | |
| 14571 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14572 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14573 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14574 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14575 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14576 | |
| 14577 | TestCompletionCallback callback; |
| 14578 | HttpRequestInfo request1; |
| 14579 | request1.method = "GET"; |
| 14580 | request1.url = GURL("https://www.a.com/"); |
| 14581 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14582 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14585 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14587 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14588 | |
| 14589 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14590 | ASSERT_TRUE(response); |
| 14591 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14592 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14593 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14594 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14595 | |
| 14596 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14597 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14598 | EXPECT_EQ("hello!", response_data); |
| 14599 | trans.reset(); |
| 14600 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14601 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14602 | |
| 14603 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14604 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14605 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14606 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14607 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14608 | HttpRequestInfo request2; |
| 14609 | request2.method = "GET"; |
| 14610 | request2.url = GURL("https://www.b.com/"); |
| 14611 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14612 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14614 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14616 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14617 | |
| 14618 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14619 | ASSERT_TRUE(response); |
| 14620 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14621 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14622 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14623 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14624 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14625 | EXPECT_EQ("hello!", response_data); |
| 14626 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14627 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14628 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14629 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14630 | |
| 14631 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14632 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14633 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14634 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14635 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14636 | HttpRequestInfo request3; |
| 14637 | request3.method = "GET"; |
| 14638 | request3.url = GURL("http://www.a.com/"); |
| 14639 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14640 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14642 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14644 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14645 | |
| 14646 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14647 | ASSERT_TRUE(response); |
| 14648 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14649 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14650 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14651 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14652 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14653 | EXPECT_EQ("hello!", response_data); |
| 14654 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14655 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14656 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14657 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14658 | } |
| 14659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14660 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14661 | HttpRequestInfo request; |
| 14662 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14663 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14664 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14667 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14668 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14669 | StaticSocketDataProvider data; |
| 14670 | data.set_connect_data(mock_connect); |
| 14671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14672 | |
| 14673 | TestCompletionCallback callback; |
| 14674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14675 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14677 | |
| 14678 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14679 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14680 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14681 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14682 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14683 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14684 | |
| 14685 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14686 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14687 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14688 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14689 | |
| 14690 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14691 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14692 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14693 | } |
| 14694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14695 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14696 | HttpRequestInfo request; |
| 14697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14698 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14702 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14703 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14704 | StaticSocketDataProvider data; |
| 14705 | data.set_connect_data(mock_connect); |
| 14706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14707 | |
| 14708 | TestCompletionCallback callback; |
| 14709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14712 | |
| 14713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14714 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14715 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14716 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14717 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14718 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14719 | |
| 14720 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14721 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14722 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14723 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14724 | |
| 14725 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14726 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14727 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14728 | } |
| 14729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14730 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14731 | HttpRequestInfo request; |
| 14732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14737 | |
| 14738 | MockWrite data_writes[] = { |
| 14739 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14740 | }; |
| 14741 | MockRead data_reads[] = { |
| 14742 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14743 | }; |
| 14744 | |
| 14745 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14746 | data_writes, arraysize(data_writes)); |
| 14747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14748 | |
| 14749 | TestCompletionCallback callback; |
| 14750 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14751 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14753 | |
| 14754 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14755 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14756 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14757 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14758 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14759 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14760 | } |
| 14761 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14762 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14763 | HttpRequestInfo request; |
| 14764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14769 | |
| 14770 | MockWrite data_writes[] = { |
| 14771 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14772 | }; |
| 14773 | MockRead data_reads[] = { |
| 14774 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14775 | }; |
| 14776 | |
| 14777 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14778 | data_writes, arraysize(data_writes)); |
| 14779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14780 | |
| 14781 | TestCompletionCallback callback; |
| 14782 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14785 | |
| 14786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14787 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14788 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14789 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14790 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14791 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14792 | } |
| 14793 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14794 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14795 | HttpRequestInfo request; |
| 14796 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14797 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14801 | |
| 14802 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14803 | MockWrite( |
| 14804 | "GET / HTTP/1.1\r\n" |
| 14805 | "Host: www.example.org\r\n" |
| 14806 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14807 | }; |
| 14808 | MockRead data_reads[] = { |
| 14809 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14810 | }; |
| 14811 | |
| 14812 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14813 | data_writes, arraysize(data_writes)); |
| 14814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14815 | |
| 14816 | TestCompletionCallback callback; |
| 14817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14818 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14820 | |
| 14821 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14822 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14823 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14824 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14825 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14826 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14827 | } |
| 14828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14829 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14830 | HttpRequestInfo request; |
| 14831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14832 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14833 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14835 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14836 | |
| 14837 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14838 | MockWrite( |
| 14839 | "GET / HTTP/1.1\r\n" |
| 14840 | "Host: www.example.org\r\n" |
| 14841 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14842 | }; |
| 14843 | MockRead data_reads[] = { |
| 14844 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14845 | }; |
| 14846 | |
| 14847 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14848 | data_writes, arraysize(data_writes)); |
| 14849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14850 | |
| 14851 | TestCompletionCallback callback; |
| 14852 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14853 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14855 | |
| 14856 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14857 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14858 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14859 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14860 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14861 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14862 | } |
| 14863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14864 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14865 | HttpRequestInfo request; |
| 14866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14867 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14868 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14871 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14872 | |
| 14873 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14874 | MockWrite( |
| 14875 | "GET / HTTP/1.1\r\n" |
| 14876 | "Host: www.example.org\r\n" |
| 14877 | "Connection: keep-alive\r\n" |
| 14878 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14879 | }; |
| 14880 | MockRead data_reads[] = { |
| 14881 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14882 | "Content-Length: 5\r\n\r\n" |
| 14883 | "hello"), |
| 14884 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14885 | }; |
| 14886 | |
| 14887 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14888 | data_writes, arraysize(data_writes)); |
| 14889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14890 | |
| 14891 | TestCompletionCallback callback; |
| 14892 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14893 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14895 | |
| 14896 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14897 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14898 | |
| 14899 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14900 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14901 | std::string foo; |
| 14902 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14903 | EXPECT_EQ("bar", foo); |
| 14904 | } |
| 14905 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14906 | namespace { |
| 14907 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14908 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14909 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14910 | public base::SupportsWeakPtr<FakeStream> { |
| 14911 | public: |
| 14912 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14913 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14914 | |
| 14915 | RequestPriority priority() const { return priority_; } |
| 14916 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14917 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14918 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14919 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14920 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14921 | return ERR_IO_PENDING; |
| 14922 | } |
| 14923 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14924 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14925 | HttpResponseInfo* response, |
| 14926 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14927 | ADD_FAILURE(); |
| 14928 | return ERR_UNEXPECTED; |
| 14929 | } |
| 14930 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14931 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14932 | ADD_FAILURE(); |
| 14933 | return ERR_UNEXPECTED; |
| 14934 | } |
| 14935 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14936 | int ReadResponseBody(IOBuffer* buf, |
| 14937 | int buf_len, |
| 14938 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14939 | ADD_FAILURE(); |
| 14940 | return ERR_UNEXPECTED; |
| 14941 | } |
| 14942 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14943 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14944 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14945 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14946 | ADD_FAILURE(); |
| 14947 | return false; |
| 14948 | } |
| 14949 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14950 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14951 | ADD_FAILURE(); |
| 14952 | return false; |
| 14953 | } |
| 14954 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14955 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14956 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14957 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14958 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14959 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14960 | ADD_FAILURE(); |
| 14961 | return 0; |
| 14962 | } |
| 14963 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14964 | int64_t GetTotalSentBytes() const override { |
| 14965 | ADD_FAILURE(); |
| 14966 | return 0; |
| 14967 | } |
| 14968 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14969 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14970 | ADD_FAILURE(); |
| 14971 | return false; |
| 14972 | } |
| 14973 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 14974 | bool GetAlternativeService( |
| 14975 | AlternativeService* alternative_service) const override { |
| 14976 | ADD_FAILURE(); |
| 14977 | return false; |
| 14978 | } |
| 14979 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14980 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14981 | |
| 14982 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14983 | ADD_FAILURE(); |
| 14984 | } |
| 14985 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14986 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14987 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 14988 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 14989 | TokenBindingType tb_type, |
| 14990 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14991 | ADD_FAILURE(); |
| 14992 | return ERR_NOT_IMPLEMENTED; |
| 14993 | } |
| 14994 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14995 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14996 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14997 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14998 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14999 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15000 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15001 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15002 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15003 | private: |
| 15004 | RequestPriority priority_; |
| 15005 | |
| 15006 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15007 | }; |
| 15008 | |
| 15009 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15010 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15011 | class FakeStreamRequest : public HttpStreamRequest, |
| 15012 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15013 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15014 | FakeStreamRequest(RequestPriority priority, |
| 15015 | HttpStreamRequest::Delegate* delegate) |
| 15016 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15017 | delegate_(delegate), |
| 15018 | websocket_stream_create_helper_(NULL) {} |
| 15019 | |
| 15020 | FakeStreamRequest(RequestPriority priority, |
| 15021 | HttpStreamRequest::Delegate* delegate, |
| 15022 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15023 | : priority_(priority), |
| 15024 | delegate_(delegate), |
| 15025 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15026 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15027 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15028 | |
| 15029 | RequestPriority priority() const { return priority_; } |
| 15030 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15031 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15032 | websocket_stream_create_helper() const { |
| 15033 | return websocket_stream_create_helper_; |
| 15034 | } |
| 15035 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15036 | // Create a new FakeStream and pass it to the request's |
| 15037 | // delegate. Returns a weak pointer to the FakeStream. |
| 15038 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 15039 | FakeStream* fake_stream = new FakeStream(priority_); |
| 15040 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15041 | // immediately delete |fake_stream|. |
| 15042 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 15043 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 15044 | return weak_stream; |
| 15045 | } |
| 15046 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15047 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15048 | ADD_FAILURE(); |
| 15049 | return ERR_UNEXPECTED; |
| 15050 | } |
| 15051 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15052 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15053 | ADD_FAILURE(); |
| 15054 | return LoadState(); |
| 15055 | } |
| 15056 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15057 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15058 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15059 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15060 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15061 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15062 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15063 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15064 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15065 | const ConnectionAttempts& connection_attempts() const override { |
| 15066 | static ConnectionAttempts no_attempts; |
| 15067 | return no_attempts; |
| 15068 | } |
| 15069 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15070 | private: |
| 15071 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15072 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15073 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15074 | |
| 15075 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15076 | }; |
| 15077 | |
| 15078 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15079 | class FakeStreamFactory : public HttpStreamFactory { |
| 15080 | public: |
| 15081 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15082 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15083 | |
| 15084 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15085 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15086 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15087 | return last_stream_request_; |
| 15088 | } |
| 15089 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15090 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 15091 | RequestPriority priority, |
| 15092 | const SSLConfig& server_ssl_config, |
| 15093 | const SSLConfig& proxy_ssl_config, |
| 15094 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15095 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15096 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15097 | const NetLogWithSource& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15098 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15099 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 15100 | return fake_request; |
| 15101 | } |
| 15102 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 15103 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15104 | const HttpRequestInfo& info, |
| 15105 | RequestPriority priority, |
| 15106 | const SSLConfig& server_ssl_config, |
| 15107 | const SSLConfig& proxy_ssl_config, |
| 15108 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15109 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15110 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15111 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15112 | NOTREACHED(); |
| 15113 | return nullptr; |
| 15114 | } |
| 15115 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15116 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15117 | const HttpRequestInfo& info, |
| 15118 | RequestPriority priority, |
| 15119 | const SSLConfig& server_ssl_config, |
| 15120 | const SSLConfig& proxy_ssl_config, |
| 15121 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15122 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15123 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15124 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15125 | const NetLogWithSource& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15126 | FakeStreamRequest* fake_request = |
| 15127 | new FakeStreamRequest(priority, delegate, create_helper); |
| 15128 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 15129 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15130 | } |
| 15131 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15132 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15133 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15134 | ADD_FAILURE(); |
| 15135 | } |
| 15136 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15137 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15138 | ADD_FAILURE(); |
| 15139 | return NULL; |
| 15140 | } |
| 15141 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15142 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15143 | const std::string& parent_absolute_name) const override { |
| 15144 | ADD_FAILURE(); |
| 15145 | } |
| 15146 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15147 | private: |
| 15148 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15149 | |
| 15150 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15151 | }; |
| 15152 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15153 | // TODO(ricea): Maybe unify this with the one in |
| 15154 | // url_request_http_job_unittest.cc ? |
| 15155 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15156 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15157 | FakeWebSocketBasicHandshakeStream( |
| 15158 | std::unique_ptr<ClientSocketHandle> connection, |
| 15159 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15160 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15161 | |
| 15162 | // Fake implementation of HttpStreamBase methods. |
| 15163 | // This ends up being quite "real" because this object has to really send data |
| 15164 | // on the mock socket. It might be easier to use the real implementation, but |
| 15165 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15166 | // difficult. |
| 15167 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15168 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15169 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15170 | const CompletionCallback& callback) override { |
| 15171 | state_.Initialize(request_info, priority, net_log, callback); |
| 15172 | return OK; |
| 15173 | } |
| 15174 | |
| 15175 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15176 | HttpResponseInfo* response, |
| 15177 | const CompletionCallback& callback) override { |
| 15178 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15179 | response, callback); |
| 15180 | } |
| 15181 | |
| 15182 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15183 | return parser()->ReadResponseHeaders(callback); |
| 15184 | } |
| 15185 | |
| 15186 | int ReadResponseBody(IOBuffer* buf, |
| 15187 | int buf_len, |
| 15188 | const CompletionCallback& callback) override { |
| 15189 | NOTREACHED(); |
| 15190 | return ERR_IO_PENDING; |
| 15191 | } |
| 15192 | |
| 15193 | void Close(bool not_reusable) override { |
| 15194 | if (parser()) |
| 15195 | parser()->Close(true); |
| 15196 | } |
| 15197 | |
| 15198 | bool IsResponseBodyComplete() const override { |
| 15199 | NOTREACHED(); |
| 15200 | return false; |
| 15201 | } |
| 15202 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15203 | bool IsConnectionReused() const override { |
| 15204 | NOTREACHED(); |
| 15205 | return false; |
| 15206 | } |
| 15207 | void SetConnectionReused() override { NOTREACHED(); } |
| 15208 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15209 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15210 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15211 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15212 | NOTREACHED(); |
| 15213 | return 0; |
| 15214 | } |
| 15215 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15216 | int64_t GetTotalSentBytes() const override { |
| 15217 | NOTREACHED(); |
| 15218 | return 0; |
| 15219 | } |
| 15220 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15221 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15222 | NOTREACHED(); |
| 15223 | return false; |
| 15224 | } |
| 15225 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15226 | bool GetAlternativeService( |
| 15227 | AlternativeService* alternative_service) const override { |
| 15228 | ADD_FAILURE(); |
| 15229 | return false; |
| 15230 | } |
| 15231 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15232 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15233 | |
| 15234 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15235 | NOTREACHED(); |
| 15236 | } |
| 15237 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15238 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15239 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15240 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15241 | TokenBindingType tb_type, |
| 15242 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15243 | ADD_FAILURE(); |
| 15244 | return ERR_NOT_IMPLEMENTED; |
| 15245 | } |
| 15246 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15247 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15248 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15249 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15250 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15251 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15252 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15253 | HttpStream* RenewStreamForAuth() override { |
| 15254 | NOTREACHED(); |
| 15255 | return nullptr; |
| 15256 | } |
| 15257 | |
| 15258 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15259 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15260 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15261 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15262 | } |
| 15263 | |
| 15264 | private: |
| 15265 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15266 | HttpBasicState state_; |
| 15267 | |
| 15268 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15269 | }; |
| 15270 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15271 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15272 | // worth doing. |
| 15273 | class FakeWebSocketStreamCreateHelper : |
| 15274 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15275 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15276 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15277 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15278 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15279 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15280 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15281 | } |
| 15282 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15283 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15284 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15285 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15286 | NOTREACHED(); |
| 15287 | return NULL; |
| 15288 | }; |
| 15289 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15290 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15291 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15292 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15293 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15294 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15295 | } |
| 15296 | }; |
| 15297 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15298 | } // namespace |
| 15299 | |
| 15300 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15301 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15302 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15304 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15305 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15306 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15307 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15308 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15309 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15310 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15311 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15312 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15313 | TestCompletionCallback callback; |
| 15314 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15315 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15316 | |
| 15317 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15318 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15319 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15320 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15321 | } |
| 15322 | |
| 15323 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15324 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15325 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15326 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15327 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15328 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15329 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15330 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15331 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15332 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15333 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15334 | TestCompletionCallback callback; |
| 15335 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15336 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15337 | |
| 15338 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15339 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15340 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15341 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15342 | |
| 15343 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15344 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15345 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15346 | } |
| 15347 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15348 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15349 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15350 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15352 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15353 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15354 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15355 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15356 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15357 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15358 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15359 | TestCompletionCallback callback; |
| 15360 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15361 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15362 | |
| 15363 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15364 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15365 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15366 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15367 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15368 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15369 | |
| 15370 | trans.SetPriority(LOWEST); |
| 15371 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15372 | } |
| 15373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15374 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15375 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15376 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15377 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15378 | std::string test_cases[] = {"ws://www.example.org/", |
| 15379 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15380 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15382 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15383 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15384 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15385 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15386 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15387 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15388 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15389 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15390 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15391 | &websocket_stream_create_helper); |
| 15392 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15393 | TestCompletionCallback callback; |
| 15394 | request.method = "GET"; |
| 15395 | request.url = GURL(test_cases[i]); |
| 15396 | |
| 15397 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15398 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15399 | |
| 15400 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15401 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15402 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15403 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15404 | fake_request->websocket_stream_create_helper()); |
| 15405 | } |
| 15406 | } |
| 15407 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15408 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15409 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15410 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15411 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15412 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15413 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15414 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15415 | |
| 15416 | // Set up SSL request. |
| 15417 | |
| 15418 | HttpRequestInfo ssl_request; |
| 15419 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15420 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15421 | |
| 15422 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15423 | MockWrite( |
| 15424 | "GET / HTTP/1.1\r\n" |
| 15425 | "Host: www.example.org\r\n" |
| 15426 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15427 | }; |
| 15428 | MockRead ssl_reads[] = { |
| 15429 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15430 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15431 | MockRead("hello world"), |
| 15432 | MockRead(SYNCHRONOUS, OK), |
| 15433 | }; |
| 15434 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15435 | ssl_writes, arraysize(ssl_writes)); |
| 15436 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15437 | |
| 15438 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15440 | |
| 15441 | // Set up HTTP request. |
| 15442 | |
| 15443 | HttpRequestInfo http_request; |
| 15444 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15445 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15446 | |
| 15447 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15448 | MockWrite( |
| 15449 | "GET / HTTP/1.1\r\n" |
| 15450 | "Host: www.example.org\r\n" |
| 15451 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15452 | }; |
| 15453 | MockRead http_reads[] = { |
| 15454 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15455 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15456 | MockRead("falafel"), |
| 15457 | MockRead(SYNCHRONOUS, OK), |
| 15458 | }; |
| 15459 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15460 | http_writes, arraysize(http_writes)); |
| 15461 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15464 | |
| 15465 | // Start the SSL request. |
| 15466 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15467 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15468 | ASSERT_EQ(ERR_IO_PENDING, |
| 15469 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15470 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15471 | |
| 15472 | // Start the HTTP request. Pool should stall. |
| 15473 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15474 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15475 | ASSERT_EQ(ERR_IO_PENDING, |
| 15476 | http_trans.Start(&http_request, http_callback.callback(), |
| 15477 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15478 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15479 | |
| 15480 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15481 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15482 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15483 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15484 | EXPECT_EQ("hello world", response_data); |
| 15485 | |
| 15486 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15487 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15488 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15489 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15490 | |
| 15491 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15492 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15493 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15494 | EXPECT_EQ("falafel", response_data); |
| 15495 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15496 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15497 | } |
| 15498 | |
| 15499 | // Tests that when a SSL connection is established but there's no corresponding |
| 15500 | // request that needs it, the new socket is closed if the transport socket pool |
| 15501 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15502 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15503 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15504 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15505 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15506 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15507 | |
| 15508 | // Set up an ssl request. |
| 15509 | |
| 15510 | HttpRequestInfo ssl_request; |
| 15511 | ssl_request.method = "GET"; |
| 15512 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15513 | |
| 15514 | // No data will be sent on the SSL socket. |
| 15515 | StaticSocketDataProvider ssl_data; |
| 15516 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15517 | |
| 15518 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15520 | |
| 15521 | // Set up HTTP request. |
| 15522 | |
| 15523 | HttpRequestInfo http_request; |
| 15524 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15525 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15526 | |
| 15527 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15528 | MockWrite( |
| 15529 | "GET / HTTP/1.1\r\n" |
| 15530 | "Host: www.example.org\r\n" |
| 15531 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15532 | }; |
| 15533 | MockRead http_reads[] = { |
| 15534 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15535 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15536 | MockRead("falafel"), |
| 15537 | MockRead(SYNCHRONOUS, OK), |
| 15538 | }; |
| 15539 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15540 | http_writes, arraysize(http_writes)); |
| 15541 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15542 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15544 | |
| 15545 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15546 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15547 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15548 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15549 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15550 | |
| 15551 | // Start the HTTP request. Pool should stall. |
| 15552 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15553 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15554 | ASSERT_EQ(ERR_IO_PENDING, |
| 15555 | http_trans.Start(&http_request, http_callback.callback(), |
| 15556 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15557 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15558 | |
| 15559 | // The SSL connection will automatically be closed once the connection is |
| 15560 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15561 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15562 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15563 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15564 | EXPECT_EQ("falafel", response_data); |
| 15565 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15566 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15567 | } |
| 15568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15569 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15570 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15571 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15572 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15573 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15574 | |
| 15575 | HttpRequestInfo request; |
| 15576 | request.method = "POST"; |
| 15577 | request.url = GURL("http://www.foo.com/"); |
| 15578 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15579 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15582 | // Send headers successfully, but get an error while sending the body. |
| 15583 | MockWrite data_writes[] = { |
| 15584 | MockWrite("POST / HTTP/1.1\r\n" |
| 15585 | "Host: www.foo.com\r\n" |
| 15586 | "Connection: keep-alive\r\n" |
| 15587 | "Content-Length: 3\r\n\r\n"), |
| 15588 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15589 | }; |
| 15590 | |
| 15591 | MockRead data_reads[] = { |
| 15592 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15593 | MockRead("hello world"), |
| 15594 | MockRead(SYNCHRONOUS, OK), |
| 15595 | }; |
| 15596 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15597 | arraysize(data_writes)); |
| 15598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15599 | |
| 15600 | TestCompletionCallback callback; |
| 15601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15604 | |
| 15605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15607 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15608 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15609 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15610 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15611 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15612 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15613 | |
| 15614 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15615 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15617 | EXPECT_EQ("hello world", response_data); |
| 15618 | } |
| 15619 | |
| 15620 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15621 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15622 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15623 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15625 | MockWrite data_writes[] = { |
| 15626 | MockWrite("GET / HTTP/1.1\r\n" |
| 15627 | "Host: www.foo.com\r\n" |
| 15628 | "Connection: keep-alive\r\n\r\n"), |
| 15629 | MockWrite("POST / HTTP/1.1\r\n" |
| 15630 | "Host: www.foo.com\r\n" |
| 15631 | "Connection: keep-alive\r\n" |
| 15632 | "Content-Length: 3\r\n\r\n"), |
| 15633 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15634 | }; |
| 15635 | |
| 15636 | MockRead data_reads[] = { |
| 15637 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15638 | "Content-Length: 14\r\n\r\n"), |
| 15639 | MockRead("first response"), |
| 15640 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15641 | "Content-Length: 15\r\n\r\n"), |
| 15642 | MockRead("second response"), |
| 15643 | MockRead(SYNCHRONOUS, OK), |
| 15644 | }; |
| 15645 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15646 | arraysize(data_writes)); |
| 15647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15648 | |
| 15649 | TestCompletionCallback callback; |
| 15650 | HttpRequestInfo request1; |
| 15651 | request1.method = "GET"; |
| 15652 | request1.url = GURL("http://www.foo.com/"); |
| 15653 | request1.load_flags = 0; |
| 15654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15655 | std::unique_ptr<HttpNetworkTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15657 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15659 | |
| 15660 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15661 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15662 | |
| 15663 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15664 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15665 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15666 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15667 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15668 | |
| 15669 | std::string response_data1; |
| 15670 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15671 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15672 | EXPECT_EQ("first response", response_data1); |
| 15673 | // Delete the transaction to release the socket back into the socket pool. |
| 15674 | trans1.reset(); |
| 15675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15676 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15677 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15678 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15679 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15680 | |
| 15681 | HttpRequestInfo request2; |
| 15682 | request2.method = "POST"; |
| 15683 | request2.url = GURL("http://www.foo.com/"); |
| 15684 | request2.upload_data_stream = &upload_data_stream; |
| 15685 | request2.load_flags = 0; |
| 15686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15687 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15688 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15690 | |
| 15691 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15692 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15694 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15695 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15696 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15697 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15698 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15699 | |
| 15700 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15701 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15702 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15703 | EXPECT_EQ("second response", response_data2); |
| 15704 | } |
| 15705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15706 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15707 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15708 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15709 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15710 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15711 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15712 | |
| 15713 | HttpRequestInfo request; |
| 15714 | request.method = "POST"; |
| 15715 | request.url = GURL("http://www.foo.com/"); |
| 15716 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15720 | // Send headers successfully, but get an error while sending the body. |
| 15721 | MockWrite data_writes[] = { |
| 15722 | MockWrite("POST / HTTP/1.1\r\n" |
| 15723 | "Host: www.foo.com\r\n" |
| 15724 | "Connection: keep-alive\r\n" |
| 15725 | "Content-Length: 3\r\n\r\n" |
| 15726 | "fo"), |
| 15727 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15728 | }; |
| 15729 | |
| 15730 | MockRead data_reads[] = { |
| 15731 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15732 | MockRead("hello world"), |
| 15733 | MockRead(SYNCHRONOUS, OK), |
| 15734 | }; |
| 15735 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15736 | arraysize(data_writes)); |
| 15737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15738 | |
| 15739 | TestCompletionCallback callback; |
| 15740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15743 | |
| 15744 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15745 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15747 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15748 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15749 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15750 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15751 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15752 | |
| 15753 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15754 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15755 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15756 | EXPECT_EQ("hello world", response_data); |
| 15757 | } |
| 15758 | |
| 15759 | // This tests the more common case than the previous test, where headers and |
| 15760 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15761 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15762 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15763 | |
| 15764 | HttpRequestInfo request; |
| 15765 | request.method = "POST"; |
| 15766 | request.url = GURL("http://www.foo.com/"); |
| 15767 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15771 | // Send headers successfully, but get an error while sending the body. |
| 15772 | MockWrite data_writes[] = { |
| 15773 | MockWrite("POST / HTTP/1.1\r\n" |
| 15774 | "Host: www.foo.com\r\n" |
| 15775 | "Connection: keep-alive\r\n" |
| 15776 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15777 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15778 | }; |
| 15779 | |
| 15780 | MockRead data_reads[] = { |
| 15781 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15782 | MockRead("hello world"), |
| 15783 | MockRead(SYNCHRONOUS, OK), |
| 15784 | }; |
| 15785 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15786 | arraysize(data_writes)); |
| 15787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15788 | |
| 15789 | TestCompletionCallback callback; |
| 15790 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15791 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15793 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15794 | // they can't be merged with the body in a single send. Not currently |
| 15795 | // necessary since a chunked body is never merged with headers, but this makes |
| 15796 | // the test more future proof. |
| 15797 | base::RunLoop().RunUntilIdle(); |
| 15798 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15799 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15800 | |
| 15801 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15804 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15805 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15806 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15807 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15808 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15809 | |
| 15810 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15811 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15812 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15813 | EXPECT_EQ("hello world", response_data); |
| 15814 | } |
| 15815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15816 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15817 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15818 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15819 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15820 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15821 | |
| 15822 | HttpRequestInfo request; |
| 15823 | request.method = "POST"; |
| 15824 | request.url = GURL("http://www.foo.com/"); |
| 15825 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15826 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15829 | |
| 15830 | MockWrite data_writes[] = { |
| 15831 | MockWrite("POST / HTTP/1.1\r\n" |
| 15832 | "Host: www.foo.com\r\n" |
| 15833 | "Connection: keep-alive\r\n" |
| 15834 | "Content-Length: 3\r\n\r\n"), |
| 15835 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15836 | }; |
| 15837 | |
| 15838 | MockRead data_reads[] = { |
| 15839 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15840 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15841 | MockRead("hello world"), |
| 15842 | MockRead(SYNCHRONOUS, OK), |
| 15843 | }; |
| 15844 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15845 | arraysize(data_writes)); |
| 15846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15847 | |
| 15848 | TestCompletionCallback callback; |
| 15849 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15850 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15851 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15852 | |
| 15853 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15856 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15857 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15858 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15859 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15860 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15861 | |
| 15862 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15863 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15864 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15865 | EXPECT_EQ("hello world", response_data); |
| 15866 | } |
| 15867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15868 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15869 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15870 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15871 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15872 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15873 | |
| 15874 | HttpRequestInfo request; |
| 15875 | request.method = "POST"; |
| 15876 | request.url = GURL("http://www.foo.com/"); |
| 15877 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15881 | // Send headers successfully, but get an error while sending the body. |
| 15882 | MockWrite data_writes[] = { |
| 15883 | MockWrite("POST / HTTP/1.1\r\n" |
| 15884 | "Host: www.foo.com\r\n" |
| 15885 | "Connection: keep-alive\r\n" |
| 15886 | "Content-Length: 3\r\n\r\n"), |
| 15887 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15888 | }; |
| 15889 | |
| 15890 | MockRead data_reads[] = { |
| 15891 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15892 | MockRead("hello world"), |
| 15893 | MockRead(SYNCHRONOUS, OK), |
| 15894 | }; |
| 15895 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15896 | arraysize(data_writes)); |
| 15897 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15898 | |
| 15899 | TestCompletionCallback callback; |
| 15900 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15901 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15903 | |
| 15904 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15905 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15906 | } |
| 15907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15908 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15909 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15910 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15911 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15912 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15913 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15914 | |
| 15915 | HttpRequestInfo request; |
| 15916 | request.method = "POST"; |
| 15917 | request.url = GURL("http://www.foo.com/"); |
| 15918 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15922 | // Send headers successfully, but get an error while sending the body. |
| 15923 | MockWrite data_writes[] = { |
| 15924 | MockWrite("POST / HTTP/1.1\r\n" |
| 15925 | "Host: www.foo.com\r\n" |
| 15926 | "Connection: keep-alive\r\n" |
| 15927 | "Content-Length: 3\r\n\r\n"), |
| 15928 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15929 | }; |
| 15930 | |
| 15931 | MockRead data_reads[] = { |
| 15932 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15933 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15934 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15935 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15936 | MockRead(SYNCHRONOUS, OK), |
| 15937 | }; |
| 15938 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15939 | arraysize(data_writes)); |
| 15940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15941 | |
| 15942 | TestCompletionCallback callback; |
| 15943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15946 | |
| 15947 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15948 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15949 | } |
| 15950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15951 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15952 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15953 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15954 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15955 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15956 | |
| 15957 | HttpRequestInfo request; |
| 15958 | request.method = "POST"; |
| 15959 | request.url = GURL("http://www.foo.com/"); |
| 15960 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15961 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15963 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15964 | // Send headers successfully, but get an error while sending the body. |
| 15965 | MockWrite data_writes[] = { |
| 15966 | MockWrite("POST / HTTP/1.1\r\n" |
| 15967 | "Host: www.foo.com\r\n" |
| 15968 | "Connection: keep-alive\r\n" |
| 15969 | "Content-Length: 3\r\n\r\n"), |
| 15970 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15971 | }; |
| 15972 | |
| 15973 | MockRead data_reads[] = { |
| 15974 | MockRead("HTTP 0.9 rocks!"), |
| 15975 | MockRead(SYNCHRONOUS, OK), |
| 15976 | }; |
| 15977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15978 | arraysize(data_writes)); |
| 15979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15980 | |
| 15981 | TestCompletionCallback callback; |
| 15982 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15983 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15985 | |
| 15986 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15987 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15988 | } |
| 15989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15990 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15991 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15992 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15993 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15994 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15995 | |
| 15996 | HttpRequestInfo request; |
| 15997 | request.method = "POST"; |
| 15998 | request.url = GURL("http://www.foo.com/"); |
| 15999 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16003 | // Send headers successfully, but get an error while sending the body. |
| 16004 | MockWrite data_writes[] = { |
| 16005 | MockWrite("POST / HTTP/1.1\r\n" |
| 16006 | "Host: www.foo.com\r\n" |
| 16007 | "Connection: keep-alive\r\n" |
| 16008 | "Content-Length: 3\r\n\r\n"), |
| 16009 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16010 | }; |
| 16011 | |
| 16012 | MockRead data_reads[] = { |
| 16013 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16014 | MockRead(SYNCHRONOUS, OK), |
| 16015 | }; |
| 16016 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16017 | arraysize(data_writes)); |
| 16018 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16019 | |
| 16020 | TestCompletionCallback callback; |
| 16021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16022 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16024 | |
| 16025 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16026 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16027 | } |
| 16028 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16029 | // Verify that proxy headers are not sent to the destination server when |
| 16030 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16031 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16032 | HttpRequestInfo request; |
| 16033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16034 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16035 | AddWebSocketHeaders(&request.extra_headers); |
| 16036 | |
| 16037 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16038 | session_deps_.proxy_service = |
| 16039 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16042 | |
| 16043 | // Since a proxy is configured, try to establish a tunnel. |
| 16044 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16045 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16046 | "Host: www.example.org:443\r\n" |
| 16047 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16048 | |
| 16049 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16050 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16051 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16052 | "Host: www.example.org:443\r\n" |
| 16053 | "Proxy-Connection: keep-alive\r\n" |
| 16054 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16055 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16056 | MockWrite("GET / HTTP/1.1\r\n" |
| 16057 | "Host: www.example.org\r\n" |
| 16058 | "Connection: Upgrade\r\n" |
| 16059 | "Upgrade: websocket\r\n" |
| 16060 | "Origin: http://www.example.org\r\n" |
| 16061 | "Sec-WebSocket-Version: 13\r\n" |
| 16062 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16063 | }; |
| 16064 | |
| 16065 | // The proxy responds to the connect with a 407, using a persistent |
| 16066 | // connection. |
| 16067 | MockRead data_reads[] = { |
| 16068 | // No credentials. |
| 16069 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16070 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16071 | MockRead("Content-Length: 0\r\n"), |
| 16072 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16073 | |
| 16074 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16075 | |
| 16076 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16077 | MockRead("Upgrade: websocket\r\n"), |
| 16078 | MockRead("Connection: Upgrade\r\n"), |
| 16079 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16080 | }; |
| 16081 | |
| 16082 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16083 | arraysize(data_writes)); |
| 16084 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16085 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16089 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16090 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16091 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16092 | &websocket_stream_create_helper); |
| 16093 | |
| 16094 | { |
| 16095 | TestCompletionCallback callback; |
| 16096 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16097 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16099 | |
| 16100 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16101 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16102 | } |
| 16103 | |
| 16104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16105 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16106 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16107 | EXPECT_EQ(407, response->headers->response_code()); |
| 16108 | |
| 16109 | { |
| 16110 | TestCompletionCallback callback; |
| 16111 | |
| 16112 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16113 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16115 | |
| 16116 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16117 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16118 | } |
| 16119 | |
| 16120 | response = trans->GetResponseInfo(); |
| 16121 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16122 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16123 | |
| 16124 | EXPECT_EQ(101, response->headers->response_code()); |
| 16125 | |
| 16126 | trans.reset(); |
| 16127 | session->CloseAllConnections(); |
| 16128 | } |
| 16129 | |
| 16130 | // Verify that proxy headers are not sent to the destination server when |
| 16131 | // establishing a tunnel for an insecure WebSocket connection. |
| 16132 | // This requires the authentication info to be injected into the auth cache |
| 16133 | // due to crbug.com/395064 |
| 16134 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16135 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16136 | HttpRequestInfo request; |
| 16137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16138 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16139 | AddWebSocketHeaders(&request.extra_headers); |
| 16140 | |
| 16141 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16142 | session_deps_.proxy_service = |
| 16143 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16144 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16146 | |
| 16147 | MockWrite data_writes[] = { |
| 16148 | // Try to establish a tunnel for the WebSocket connection, with |
| 16149 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16150 | // they cannot and will not use the same TCP/IP connection as the |
| 16151 | // preflight HTTP request. |
| 16152 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16153 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16154 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16155 | "Proxy-Connection: keep-alive\r\n" |
| 16156 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16157 | |
| 16158 | MockWrite( |
| 16159 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16160 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16161 | "Connection: Upgrade\r\n" |
| 16162 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16163 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16164 | "Sec-WebSocket-Version: 13\r\n" |
| 16165 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16166 | }; |
| 16167 | |
| 16168 | MockRead data_reads[] = { |
| 16169 | // HTTP CONNECT with credentials. |
| 16170 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16171 | |
| 16172 | // WebSocket connection established inside tunnel. |
| 16173 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16174 | MockRead("Upgrade: websocket\r\n"), |
| 16175 | MockRead("Connection: Upgrade\r\n"), |
| 16176 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16177 | }; |
| 16178 | |
| 16179 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16180 | arraysize(data_writes)); |
| 16181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16182 | |
| 16183 | session->http_auth_cache()->Add( |
| 16184 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16185 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16187 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16188 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16189 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16190 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16191 | &websocket_stream_create_helper); |
| 16192 | |
| 16193 | TestCompletionCallback callback; |
| 16194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16195 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16197 | |
| 16198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16199 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16200 | |
| 16201 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16202 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16203 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16204 | |
| 16205 | EXPECT_EQ(101, response->headers->response_code()); |
| 16206 | |
| 16207 | trans.reset(); |
| 16208 | session->CloseAllConnections(); |
| 16209 | } |
| 16210 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16211 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16212 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16213 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16214 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16215 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16216 | |
| 16217 | HttpRequestInfo request; |
| 16218 | request.method = "POST"; |
| 16219 | request.url = GURL("http://www.foo.com/"); |
| 16220 | request.upload_data_stream = &upload_data_stream; |
| 16221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16224 | MockWrite data_writes[] = { |
| 16225 | MockWrite("POST / HTTP/1.1\r\n" |
| 16226 | "Host: www.foo.com\r\n" |
| 16227 | "Connection: keep-alive\r\n" |
| 16228 | "Content-Length: 3\r\n\r\n"), |
| 16229 | MockWrite("foo"), |
| 16230 | }; |
| 16231 | |
| 16232 | MockRead data_reads[] = { |
| 16233 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16234 | MockRead(SYNCHRONOUS, OK), |
| 16235 | }; |
| 16236 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16237 | arraysize(data_writes)); |
| 16238 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16239 | |
| 16240 | TestCompletionCallback callback; |
| 16241 | |
| 16242 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16243 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16244 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16245 | |
| 16246 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16247 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16248 | |
| 16249 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16250 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16251 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16252 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16253 | } |
| 16254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16255 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16256 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16257 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16258 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16259 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16260 | |
| 16261 | HttpRequestInfo request; |
| 16262 | request.method = "POST"; |
| 16263 | request.url = GURL("http://www.foo.com/"); |
| 16264 | request.upload_data_stream = &upload_data_stream; |
| 16265 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16266 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16267 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16268 | MockWrite data_writes[] = { |
| 16269 | MockWrite("POST / HTTP/1.1\r\n" |
| 16270 | "Host: www.foo.com\r\n" |
| 16271 | "Connection: keep-alive\r\n" |
| 16272 | "Content-Length: 3\r\n\r\n"), |
| 16273 | MockWrite("foo"), |
| 16274 | }; |
| 16275 | |
| 16276 | MockRead data_reads[] = { |
| 16277 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16278 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16279 | MockRead(SYNCHRONOUS, OK), |
| 16280 | }; |
| 16281 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16282 | arraysize(data_writes)); |
| 16283 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16284 | |
| 16285 | TestCompletionCallback callback; |
| 16286 | |
| 16287 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16288 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16289 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16290 | |
| 16291 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16292 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16293 | |
| 16294 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16295 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16296 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16297 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16298 | } |
| 16299 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16300 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16301 | ChunkedUploadDataStream upload_data_stream(0); |
| 16302 | |
| 16303 | HttpRequestInfo request; |
| 16304 | request.method = "POST"; |
| 16305 | request.url = GURL("http://www.foo.com/"); |
| 16306 | request.upload_data_stream = &upload_data_stream; |
| 16307 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16310 | // Send headers successfully, but get an error while sending the body. |
| 16311 | MockWrite data_writes[] = { |
| 16312 | MockWrite("POST / HTTP/1.1\r\n" |
| 16313 | "Host: www.foo.com\r\n" |
| 16314 | "Connection: keep-alive\r\n" |
| 16315 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16316 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16317 | }; |
| 16318 | |
| 16319 | MockRead data_reads[] = { |
| 16320 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16321 | MockRead(SYNCHRONOUS, OK), |
| 16322 | }; |
| 16323 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16324 | arraysize(data_writes)); |
| 16325 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16326 | |
| 16327 | TestCompletionCallback callback; |
| 16328 | |
| 16329 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16330 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16331 | |
| 16332 | base::RunLoop().RunUntilIdle(); |
| 16333 | upload_data_stream.AppendData("f", 1, false); |
| 16334 | |
| 16335 | base::RunLoop().RunUntilIdle(); |
| 16336 | upload_data_stream.AppendData("oo", 2, true); |
| 16337 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16338 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16339 | |
| 16340 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16341 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16342 | |
| 16343 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16344 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16345 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16346 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16347 | } |
| 16348 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16349 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16350 | // the unthrottled state are not blocked. |
| 16351 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16352 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16353 | std::unique_ptr<HttpNetworkSession> session( |
| 16354 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16355 | |
| 16356 | // Send a simple request and make sure it goes through. |
| 16357 | HttpRequestInfo request; |
| 16358 | request.method = "GET"; |
| 16359 | request.url = GURL("http://www.example.org/"); |
| 16360 | |
| 16361 | std::unique_ptr<HttpTransaction> trans( |
| 16362 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16363 | |
| 16364 | MockWrite data_writes[] = { |
| 16365 | MockWrite("GET / HTTP/1.1\r\n" |
| 16366 | "Host: www.example.org\r\n" |
| 16367 | "Connection: keep-alive\r\n\r\n"), |
| 16368 | }; |
| 16369 | MockRead data_reads[] = { |
| 16370 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16371 | MockRead(SYNCHRONOUS, OK), |
| 16372 | }; |
| 16373 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16374 | arraysize(data_writes)); |
| 16375 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16376 | |
| 16377 | TestCompletionCallback callback; |
| 16378 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16379 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16380 | } |
| 16381 | |
| 16382 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16383 | // when the throttle is unblocked. |
| 16384 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16385 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16386 | std::unique_ptr<HttpNetworkSession> session( |
| 16387 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16388 | |
| 16389 | // Send a simple request and make sure it goes through. |
| 16390 | HttpRequestInfo request; |
| 16391 | request.method = "GET"; |
| 16392 | request.url = GURL("http://www.example.org/"); |
| 16393 | |
| 16394 | MockWrite data_writes[] = { |
| 16395 | MockWrite("GET / HTTP/1.1\r\n" |
| 16396 | "Host: www.example.org\r\n" |
| 16397 | "Connection: keep-alive\r\n\r\n"), |
| 16398 | }; |
| 16399 | MockRead data_reads[] = { |
| 16400 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16401 | MockRead(SYNCHRONOUS, OK), |
| 16402 | }; |
| 16403 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16404 | arraysize(data_writes)); |
| 16405 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16406 | |
| 16407 | // Start a request that will be throttled at start; confirm it |
| 16408 | // doesn't complete. |
| 16409 | throttler->set_throttle_new_requests(true); |
| 16410 | std::unique_ptr<HttpTransaction> trans( |
| 16411 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16412 | |
| 16413 | TestCompletionCallback callback; |
| 16414 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16416 | |
| 16417 | base::RunLoop().RunUntilIdle(); |
| 16418 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16419 | EXPECT_FALSE(callback.have_result()); |
| 16420 | |
| 16421 | // Confirm the request goes on to complete when unthrottled. |
| 16422 | throttler->UnthrottleAllRequests(); |
| 16423 | base::RunLoop().RunUntilIdle(); |
| 16424 | ASSERT_TRUE(callback.have_result()); |
| 16425 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16426 | } |
| 16427 | |
| 16428 | // Destroy a request while it's throttled. |
| 16429 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16430 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16431 | std::unique_ptr<HttpNetworkSession> session( |
| 16432 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16433 | |
| 16434 | // Send a simple request and make sure it goes through. |
| 16435 | HttpRequestInfo request; |
| 16436 | request.method = "GET"; |
| 16437 | request.url = GURL("http://www.example.org/"); |
| 16438 | |
| 16439 | MockWrite data_writes[] = { |
| 16440 | MockWrite("GET / HTTP/1.1\r\n" |
| 16441 | "Host: www.example.org\r\n" |
| 16442 | "Connection: keep-alive\r\n\r\n"), |
| 16443 | }; |
| 16444 | MockRead data_reads[] = { |
| 16445 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16446 | MockRead(SYNCHRONOUS, OK), |
| 16447 | }; |
| 16448 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16449 | arraysize(data_writes)); |
| 16450 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16451 | |
| 16452 | // Start a request that will be throttled at start; confirm it |
| 16453 | // doesn't complete. |
| 16454 | throttler->set_throttle_new_requests(true); |
| 16455 | std::unique_ptr<HttpTransaction> trans( |
| 16456 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16457 | |
| 16458 | TestCompletionCallback callback; |
| 16459 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16460 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16461 | |
| 16462 | base::RunLoop().RunUntilIdle(); |
| 16463 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16464 | EXPECT_FALSE(callback.have_result()); |
| 16465 | |
| 16466 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16467 | trans.reset(); |
| 16468 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16469 | } |
| 16470 | |
| 16471 | // Confirm the throttler receives SetPriority calls. |
| 16472 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16473 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16474 | std::unique_ptr<HttpNetworkSession> session( |
| 16475 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16476 | |
| 16477 | // Send a simple request and make sure it goes through. |
| 16478 | HttpRequestInfo request; |
| 16479 | request.method = "GET"; |
| 16480 | request.url = GURL("http://www.example.org/"); |
| 16481 | |
| 16482 | MockWrite data_writes[] = { |
| 16483 | MockWrite("GET / HTTP/1.1\r\n" |
| 16484 | "Host: www.example.org\r\n" |
| 16485 | "Connection: keep-alive\r\n\r\n"), |
| 16486 | }; |
| 16487 | MockRead data_reads[] = { |
| 16488 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16489 | MockRead(SYNCHRONOUS, OK), |
| 16490 | }; |
| 16491 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16492 | arraysize(data_writes)); |
| 16493 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16494 | |
| 16495 | throttler->set_throttle_new_requests(true); |
| 16496 | std::unique_ptr<HttpTransaction> trans( |
| 16497 | new HttpNetworkTransaction(IDLE, session.get())); |
| 16498 | // Start the transaction to associate a throttle with it. |
| 16499 | TestCompletionCallback callback; |
| 16500 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16501 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16502 | |
| 16503 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16504 | trans->SetPriority(LOW); |
| 16505 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16506 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16507 | |
| 16508 | throttler->UnthrottleAllRequests(); |
| 16509 | base::RunLoop().RunUntilIdle(); |
| 16510 | ASSERT_TRUE(callback.have_result()); |
| 16511 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16512 | } |
| 16513 | |
| 16514 | // Confirm that unthrottling from a SetPriority call by the |
| 16515 | // throttler works properly. |
| 16516 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16517 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16518 | std::unique_ptr<HttpNetworkSession> session( |
| 16519 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16520 | |
| 16521 | // Send a simple request and make sure it goes through. |
| 16522 | HttpRequestInfo request; |
| 16523 | request.method = "GET"; |
| 16524 | request.url = GURL("http://www.example.org/"); |
| 16525 | |
| 16526 | MockWrite data_writes[] = { |
| 16527 | MockWrite("GET / HTTP/1.1\r\n" |
| 16528 | "Host: www.example.org\r\n" |
| 16529 | "Connection: keep-alive\r\n\r\n"), |
| 16530 | }; |
| 16531 | MockRead data_reads[] = { |
| 16532 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16533 | MockRead(SYNCHRONOUS, OK), |
| 16534 | }; |
| 16535 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16536 | arraysize(data_writes)); |
| 16537 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16538 | |
| 16539 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16540 | data_writes, arraysize(data_writes)); |
| 16541 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16542 | |
| 16543 | // Start a request that will be throttled at start; confirm it |
| 16544 | // doesn't complete. |
| 16545 | throttler->set_throttle_new_requests(true); |
| 16546 | std::unique_ptr<HttpTransaction> trans( |
| 16547 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16548 | |
| 16549 | TestCompletionCallback callback; |
| 16550 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16551 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16552 | |
| 16553 | base::RunLoop().RunUntilIdle(); |
| 16554 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16555 | EXPECT_FALSE(callback.have_result()); |
| 16556 | |
| 16557 | // Create a new request, call SetPriority on it to unthrottle, |
| 16558 | // and make sure that allows the original request to complete. |
| 16559 | std::unique_ptr<HttpTransaction> trans1( |
| 16560 | new HttpNetworkTransaction(LOW, session.get())); |
| 16561 | throttler->set_priority_change_closure( |
| 16562 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16563 | base::Unretained(throttler))); |
| 16564 | |
| 16565 | // Start the transaction to associate a throttle with it. |
| 16566 | TestCompletionCallback callback1; |
| 16567 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16568 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16569 | |
| 16570 | trans1->SetPriority(IDLE); |
| 16571 | |
| 16572 | base::RunLoop().RunUntilIdle(); |
| 16573 | ASSERT_TRUE(callback.have_result()); |
| 16574 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16575 | ASSERT_TRUE(callback1.have_result()); |
| 16576 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16577 | } |
| 16578 | |
| 16579 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
| 16580 | void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {} |
| 16581 | |
| 16582 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16583 | // throttler works properly. |
| 16584 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16585 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16586 | std::unique_ptr<HttpNetworkSession> session( |
| 16587 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16588 | |
| 16589 | // Send a simple request and make sure it goes through. |
| 16590 | HttpRequestInfo request; |
| 16591 | request.method = "GET"; |
| 16592 | request.url = GURL("http://www.example.org/"); |
| 16593 | |
| 16594 | MockWrite data_writes[] = { |
| 16595 | MockWrite("GET / HTTP/1.1\r\n" |
| 16596 | "Host: www.example.org\r\n" |
| 16597 | "Connection: keep-alive\r\n\r\n"), |
| 16598 | }; |
| 16599 | MockRead data_reads[] = { |
| 16600 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16601 | MockRead(SYNCHRONOUS, OK), |
| 16602 | }; |
| 16603 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16604 | arraysize(data_writes)); |
| 16605 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16606 | |
| 16607 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16608 | data_writes, arraysize(data_writes)); |
| 16609 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16610 | |
| 16611 | // Start a request that will be throttled at start; confirm it |
| 16612 | // doesn't complete. |
| 16613 | throttler->set_throttle_new_requests(true); |
| 16614 | std::unique_ptr<HttpTransaction> trans( |
| 16615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16616 | |
| 16617 | TestCompletionCallback callback; |
| 16618 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16620 | |
| 16621 | base::RunLoop().RunUntilIdle(); |
| 16622 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16623 | EXPECT_FALSE(callback.have_result()); |
| 16624 | |
| 16625 | // Arrange for the set priority call on the above transaction to delete |
| 16626 | // the transaction. |
| 16627 | HttpTransaction* trans_ptr(trans.get()); |
| 16628 | throttler->set_priority_change_closure( |
| 16629 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16630 | |
| 16631 | // Call it and check results (partially a "doesn't crash" test). |
| 16632 | trans_ptr->SetPriority(IDLE); |
| 16633 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16634 | |
| 16635 | base::RunLoop().RunUntilIdle(); |
| 16636 | ASSERT_FALSE(callback.have_result()); |
| 16637 | } |
| 16638 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16639 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16640 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 16641 | // Required by ChannelIDService. |
| 16642 | base::test::ScopedTaskScheduler scoped_task_scheduler( |
| 16643 | base::MessageLoop::current()); |
| 16644 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16645 | const std::string https_url = "https://www.example.com"; |
| 16646 | HttpRequestInfo request; |
| 16647 | request.url = GURL(https_url); |
| 16648 | request.method = "GET"; |
| 16649 | |
| 16650 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16651 | ssl.token_binding_negotiated = true; |
| 16652 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16653 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16654 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16655 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16656 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16657 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16658 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16659 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16660 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 16662 | session_deps_.channel_id_service.reset( |
| 16663 | new ChannelIDService(new DefaultChannelIDStore(nullptr))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16665 | |
| 16666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16667 | TestCompletionCallback callback; |
| 16668 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16669 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16670 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16671 | |
| 16672 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16673 | HttpRequestHeaders headers; |
| 16674 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16675 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16676 | } |
| 16677 | #endif // !defined(OS_IOS) |
| 16678 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16679 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16680 | const std::string& accept_encoding, |
| 16681 | const std::string& content_encoding, |
| 16682 | bool should_match) { |
| 16683 | HttpRequestInfo request; |
| 16684 | request.method = "GET"; |
| 16685 | request.url = GURL("http://www.foo.com/"); |
| 16686 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16687 | accept_encoding); |
| 16688 | |
| 16689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16691 | // Send headers successfully, but get an error while sending the body. |
| 16692 | MockWrite data_writes[] = { |
| 16693 | MockWrite("GET / HTTP/1.1\r\n" |
| 16694 | "Host: www.foo.com\r\n" |
| 16695 | "Connection: keep-alive\r\n" |
| 16696 | "Accept-Encoding: "), |
| 16697 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16698 | }; |
| 16699 | |
| 16700 | MockRead data_reads[] = { |
| 16701 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "), |
| 16702 | MockRead(content_encoding.data()), MockRead("\r\n\r\n"), |
| 16703 | MockRead(SYNCHRONOUS, OK), |
| 16704 | }; |
| 16705 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16706 | arraysize(data_writes)); |
| 16707 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16708 | |
| 16709 | TestCompletionCallback callback; |
| 16710 | |
| 16711 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16713 | |
| 16714 | rv = callback.WaitForResult(); |
| 16715 | if (should_match) { |
| 16716 | EXPECT_THAT(rv, IsOk()); |
| 16717 | } else { |
| 16718 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16719 | } |
| 16720 | } |
| 16721 | |
| 16722 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
| 16723 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", false); |
| 16724 | } |
| 16725 | |
| 16726 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
| 16727 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", true); |
| 16728 | } |
| 16729 | |
| 16730 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16731 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16732 | false); |
| 16733 | } |
| 16734 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16735 | } // namespace net |