[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_); |
| 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 | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 401 | session_deps_.enable_http2_alternative_service_with_different_host = 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 {} |
| 687 | int IdleSocketCount() const override { return 0; } |
| 688 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 689 | return 0; |
| 690 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 691 | LoadState GetLoadState(const std::string& group_name, |
| 692 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 693 | return LOAD_STATE_IDLE; |
| 694 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 695 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 696 | return base::TimeDelta(); |
| 697 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 698 | |
| 699 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 700 | std::string last_group_name_; |
| 701 | }; |
| 702 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 703 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 704 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 705 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 706 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 707 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 708 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 709 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 710 | CaptureGroupNameSSLSocketPool; |
| 711 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 712 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 713 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 714 | HostResolver* host_resolver, |
| 715 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 716 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 717 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 718 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 719 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 720 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 721 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 722 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 723 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 724 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 725 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 726 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 727 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 728 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 729 | : SSLClientSocketPool(0, |
| 730 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 731 | cert_verifier, |
| 732 | NULL, |
| 733 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 734 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 735 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 736 | std::string(), |
| 737 | NULL, |
| 738 | NULL, |
| 739 | NULL, |
| 740 | NULL, |
| 741 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 742 | NULL) { |
| 743 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 744 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | //----------------------------------------------------------------------------- |
| 746 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 747 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 748 | // configured for common cases. |
| 749 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 750 | if (!auth_challenge) |
| 751 | return false; |
| 752 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 753 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 755 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | return true; |
| 757 | } |
| 758 | |
| 759 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 760 | if (!auth_challenge) |
| 761 | return false; |
| 762 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 763 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 764 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 765 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 770 | if (!auth_challenge) |
| 771 | return false; |
| 772 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 773 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 774 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 775 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 776 | return true; |
| 777 | } |
| 778 | |
| 779 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 780 | if (!auth_challenge) |
| 781 | return false; |
| 782 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 783 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 785 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 786 | return true; |
| 787 | } |
| 788 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 789 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 790 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 791 | if (!auth_challenge) |
| 792 | return false; |
| 793 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 794 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 795 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 796 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 797 | return true; |
| 798 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 799 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 800 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 801 | } // namespace |
| 802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 803 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 804 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 805 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | } |
| 807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 808 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 810 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 811 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 814 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 815 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 816 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 818 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 819 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 820 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 821 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 822 | |
| 823 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 827 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 828 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 829 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 830 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 831 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 832 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 833 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 834 | EXPECT_THAT(out.rv, IsOk()); |
| 835 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 836 | EXPECT_EQ("hello world", out.response_data); |
| 837 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 838 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 839 | } |
| 840 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 841 | // Response with no status line, and a weird port. Should fail by default. |
| 842 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 843 | MockRead data_reads[] = { |
| 844 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 845 | }; |
| 846 | |
| 847 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 848 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 849 | |
| 850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 851 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 852 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 853 | std::unique_ptr<HttpTransaction> trans( |
| 854 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 855 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 856 | request.method = "GET"; |
| 857 | request.url = GURL("http://www.example.com:2000/"); |
| 858 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 859 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 860 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 861 | } |
| 862 | |
| 863 | // Response with no status line, and a weird port. Option to allow weird ports |
| 864 | // enabled. |
| 865 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 866 | MockRead data_reads[] = { |
| 867 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 868 | }; |
| 869 | |
| 870 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 872 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 874 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 875 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 876 | std::unique_ptr<HttpTransaction> trans( |
| 877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 878 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 879 | request.method = "GET"; |
| 880 | request.url = GURL("http://www.example.com:2000/"); |
| 881 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 882 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 883 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 884 | |
| 885 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 886 | ASSERT_TRUE(info->headers); |
| 887 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 888 | |
| 889 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 890 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 891 | } |
| 892 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 893 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 894 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 895 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 896 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 897 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 898 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 899 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 900 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 901 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 902 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 903 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 904 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 905 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 909 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 910 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 911 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 912 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 913 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 914 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 915 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 916 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 918 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 919 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 920 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 924 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 926 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 927 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 928 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 929 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 930 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 931 | EXPECT_THAT(out.rv, IsOk()); |
| 932 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 933 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 934 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 935 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 939 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 940 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 941 | MockRead("\n"), |
| 942 | MockRead("\n"), |
| 943 | MockRead("Q"), |
| 944 | MockRead("J"), |
| 945 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 946 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 947 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 948 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 949 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 950 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 951 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 952 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 953 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 954 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 958 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 959 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 960 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 961 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 963 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 964 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 965 | EXPECT_THAT(out.rv, IsOk()); |
| 966 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 967 | EXPECT_EQ("HTT", out.response_data); |
| 968 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 969 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 970 | } |
| 971 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 972 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 973 | // persistent connection. The response should still terminate since a 204 |
| 974 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 975 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 976 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 977 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 978 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 979 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 980 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 981 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 982 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 983 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 984 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 985 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 986 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 987 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 988 | int64_t response_size = reads_size - strlen(junk); |
| 989 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 990 | } |
| 991 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 992 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 993 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 994 | std::string final_chunk = "0\r\n\r\n"; |
| 995 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 996 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 997 | MockRead data_reads[] = { |
| 998 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 999 | MockRead("5\r\nHello\r\n"), |
| 1000 | MockRead("1\r\n"), |
| 1001 | MockRead(" \r\n"), |
| 1002 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1003 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1004 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1005 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1006 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1007 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1008 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1009 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1010 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1011 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1012 | int64_t response_size = reads_size - extra_data.size(); |
| 1013 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1014 | } |
| 1015 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1016 | // Next tests deal with http://crbug.com/56344. |
| 1017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1018 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1019 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1020 | MockRead data_reads[] = { |
| 1021 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1022 | MockRead("Content-Length: 10\r\n"), |
| 1023 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1024 | }; |
| 1025 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1026 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1027 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1028 | } |
| 1029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1030 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1031 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1032 | MockRead data_reads[] = { |
| 1033 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1034 | MockRead("Content-Length: 5\r\n"), |
| 1035 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1036 | MockRead("Hello"), |
| 1037 | }; |
| 1038 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1039 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1040 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1041 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1042 | EXPECT_EQ("Hello", out.response_data); |
| 1043 | } |
| 1044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1045 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1046 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1047 | // More than 2 dupes. |
| 1048 | { |
| 1049 | MockRead data_reads[] = { |
| 1050 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1051 | MockRead("Content-Length: 5\r\n"), |
| 1052 | MockRead("Content-Length: 5\r\n"), |
| 1053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1054 | MockRead("Hello"), |
| 1055 | }; |
| 1056 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1057 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1058 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1059 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1060 | EXPECT_EQ("Hello", out.response_data); |
| 1061 | } |
| 1062 | // HTTP/1.0 |
| 1063 | { |
| 1064 | MockRead data_reads[] = { |
| 1065 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
| 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1072 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1073 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1074 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1075 | EXPECT_EQ("Hello", out.response_data); |
| 1076 | } |
| 1077 | // 2 dupes and one mismatched. |
| 1078 | { |
| 1079 | MockRead data_reads[] = { |
| 1080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1081 | MockRead("Content-Length: 10\r\n"), |
| 1082 | MockRead("Content-Length: 10\r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1084 | }; |
| 1085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1086 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1087 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1091 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1092 | MultipleContentLengthHeadersTransferEncoding) { |
| 1093 | MockRead data_reads[] = { |
| 1094 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1095 | MockRead("Content-Length: 666\r\n"), |
| 1096 | MockRead("Content-Length: 1337\r\n"), |
| 1097 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1098 | MockRead("5\r\nHello\r\n"), |
| 1099 | MockRead("1\r\n"), |
| 1100 | MockRead(" \r\n"), |
| 1101 | MockRead("5\r\nworld\r\n"), |
| 1102 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1103 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1104 | }; |
| 1105 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1106 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1107 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1108 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1109 | EXPECT_EQ("Hello world", out.response_data); |
| 1110 | } |
| 1111 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1112 | // Next tests deal with http://crbug.com/98895. |
| 1113 | |
| 1114 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1115 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1116 | MockRead data_reads[] = { |
| 1117 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1118 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1119 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1120 | MockRead("Hello"), |
| 1121 | }; |
| 1122 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1123 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1124 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1125 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1126 | EXPECT_EQ("Hello", out.response_data); |
| 1127 | } |
| 1128 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1129 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1130 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1131 | MockRead data_reads[] = { |
| 1132 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1133 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1134 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1135 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1136 | MockRead("Hello"), |
| 1137 | }; |
| 1138 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1139 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1140 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1141 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1142 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1146 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1147 | MockRead data_reads[] = { |
| 1148 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1149 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1150 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1151 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1152 | MockRead("Hello"), |
| 1153 | }; |
| 1154 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1155 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1156 | EXPECT_THAT(out.rv, |
| 1157 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | } |
| 1159 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1160 | // Checks that two identical Location headers result in no error. |
| 1161 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1162 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1163 | MockRead data_reads[] = { |
| 1164 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1165 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1166 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1168 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1169 | }; |
| 1170 | |
| 1171 | HttpRequestInfo request; |
| 1172 | request.method = "GET"; |
| 1173 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1174 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1175 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1176 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | |
| 1178 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1181 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1183 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1185 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1186 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1188 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1189 | ASSERT_TRUE(response); |
| 1190 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1192 | std::string url; |
| 1193 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1194 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1195 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | } |
| 1197 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1198 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1199 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | MockRead data_reads[] = { |
| 1201 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1202 | MockRead("Location: http://good.com/\r\n"), |
| 1203 | MockRead("Location: http://evil.com/\r\n"), |
| 1204 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | }; |
| 1207 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1208 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1209 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | } |
| 1211 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1212 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1213 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1214 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1215 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1217 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1218 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1219 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1221 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1222 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1223 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1224 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1225 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1226 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1227 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1228 | "Host: www.example.org\r\n" |
| 1229 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1230 | }; |
| 1231 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1232 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1233 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1234 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1235 | // No response body because the test stops reading here. |
| 1236 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | }; |
| 1238 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1239 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1240 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1241 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1243 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1245 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | |
| 1248 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1251 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1252 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1253 | |
| 1254 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1255 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1256 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1257 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1258 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1259 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1260 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | |
| 1262 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1263 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1264 | bool has_server_header = response->headers->EnumerateHeader( |
| 1265 | &iter, "Server", &server_header); |
| 1266 | EXPECT_TRUE(has_server_header); |
| 1267 | EXPECT_EQ("Blah", server_header); |
| 1268 | |
| 1269 | // Reading should give EOF right away, since there is no message body |
| 1270 | // (despite non-zero content-length). |
| 1271 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1272 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1274 | EXPECT_EQ("", response_data); |
| 1275 | } |
| 1276 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1277 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1279 | |
| 1280 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1281 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1282 | MockRead("hello"), |
| 1283 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1284 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1285 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1286 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1288 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1290 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1291 | "hello", "world" |
| 1292 | }; |
| 1293 | |
| 1294 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1295 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1297 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1301 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | |
| 1306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1307 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1309 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1310 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1312 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1313 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1314 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
| 1316 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1317 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1319 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1323 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1324 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1325 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1326 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1327 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1328 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1329 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | request.method = "POST"; |
| 1331 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1332 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1334 | // Check the upload progress returned before initialization is correct. |
| 1335 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1336 | EXPECT_EQ(0u, progress.size()); |
| 1337 | EXPECT_EQ(0u, progress.position()); |
| 1338 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1341 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1343 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1344 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1345 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1346 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1348 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1351 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
| 1356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1357 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1360 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1362 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1363 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
| 1365 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1366 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1368 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | } |
| 1370 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1371 | // This test is almost the same as Ignores100 above, but the response contains |
| 1372 | // 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] | 1373 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1374 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1375 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1376 | request.method = "GET"; |
| 1377 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1378 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1380 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1381 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1382 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1383 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1384 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1386 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1387 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1388 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1391 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1393 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | |
| 1396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1399 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1400 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1402 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1404 | |
| 1405 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1406 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1407 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | EXPECT_EQ("hello world", response_data); |
| 1409 | } |
| 1410 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1411 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1412 | HttpRequestInfo request; |
| 1413 | request.method = "POST"; |
| 1414 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1418 | |
| 1419 | MockRead data_reads[] = { |
| 1420 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1421 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1422 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1423 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1425 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1426 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1427 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1428 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1430 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1431 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1433 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1434 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1435 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1436 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1437 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1438 | } |
| 1439 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1440 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1441 | HttpRequestInfo request; |
| 1442 | request.method = "POST"; |
| 1443 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1444 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1447 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1448 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1449 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1450 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1451 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1452 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1454 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1455 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1456 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1458 | |
| 1459 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1460 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1463 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1464 | const MockWrite* write_failure, |
| 1465 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1466 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1467 | request.method = "GET"; |
| 1468 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1469 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1470 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1471 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1473 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1474 | // Written data for successfully sending both requests. |
| 1475 | MockWrite data1_writes[] = { |
| 1476 | MockWrite("GET / HTTP/1.1\r\n" |
| 1477 | "Host: www.foo.com\r\n" |
| 1478 | "Connection: keep-alive\r\n\r\n"), |
| 1479 | MockWrite("GET / HTTP/1.1\r\n" |
| 1480 | "Host: www.foo.com\r\n" |
| 1481 | "Connection: keep-alive\r\n\r\n") |
| 1482 | }; |
| 1483 | |
| 1484 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1485 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1486 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1487 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1488 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1489 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1490 | |
| 1491 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1492 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1493 | data1_writes[1] = *write_failure; |
| 1494 | } else { |
| 1495 | ASSERT_TRUE(read_failure); |
| 1496 | data1_reads[2] = *read_failure; |
| 1497 | } |
| 1498 | |
| 1499 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1500 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1501 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1502 | |
| 1503 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1504 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1505 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1506 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1507 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1508 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1509 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1510 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1511 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1512 | "hello", "world" |
| 1513 | }; |
| 1514 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1515 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1516 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1517 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1520 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1521 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1522 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1523 | |
| 1524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1525 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1526 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1527 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1528 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1529 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1530 | if (i == 0) { |
| 1531 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1532 | } else { |
| 1533 | // The second request should be using a new socket. |
| 1534 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1535 | } |
| 1536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1537 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1538 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1539 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1540 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1541 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1542 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1543 | |
| 1544 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1545 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1546 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1547 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1548 | } |
| 1549 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1550 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1551 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1552 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1553 | const MockRead* read_failure, |
| 1554 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1555 | HttpRequestInfo request; |
| 1556 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1557 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1558 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1559 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1560 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1562 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1563 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1564 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1565 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1566 | ssl1.next_proto = kProtoHTTP2; |
| 1567 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1568 | } |
| 1569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1570 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1571 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1572 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1573 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1574 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1575 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1576 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1577 | SpdySerializedFrame spdy_data( |
| 1578 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1579 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1580 | // HTTP/1.1 versions of the request and response. |
| 1581 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1582 | "Host: www.foo.com\r\n" |
| 1583 | "Connection: keep-alive\r\n\r\n"; |
| 1584 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1585 | const char kHttpData[] = "hello"; |
| 1586 | |
| 1587 | std::vector<MockRead> data1_reads; |
| 1588 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1589 | if (write_failure) { |
| 1590 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1591 | data1_writes.push_back(*write_failure); |
| 1592 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1593 | } else { |
| 1594 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1595 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1596 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1597 | } else { |
| 1598 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1599 | } |
| 1600 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1601 | } |
| 1602 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1603 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1604 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1605 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1606 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1607 | std::vector<MockRead> data2_reads; |
| 1608 | std::vector<MockWrite> data2_writes; |
| 1609 | |
| 1610 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1611 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1612 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1613 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1614 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1615 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1616 | } else { |
| 1617 | data2_writes.push_back( |
| 1618 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1619 | |
| 1620 | data2_reads.push_back( |
| 1621 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1622 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1623 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1624 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1625 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1626 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1627 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1628 | |
| 1629 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1630 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1631 | // Wait for the preconnect to complete. |
| 1632 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1633 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1634 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1635 | |
| 1636 | // Make the request. |
| 1637 | TestCompletionCallback callback; |
| 1638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1640 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1641 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1643 | |
| 1644 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1645 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1646 | |
| 1647 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1648 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1649 | TestLoadTimingNotReused( |
| 1650 | load_timing_info, |
| 1651 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1653 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1654 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1655 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1656 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1657 | if (response->was_fetched_via_spdy) { |
| 1658 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1659 | } else { |
| 1660 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1661 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1662 | |
| 1663 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1664 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1665 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1666 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1667 | } |
| 1668 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1669 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1670 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1671 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1672 | } |
| 1673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1674 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1675 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1676 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1677 | } |
| 1678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1679 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1680 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1681 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1682 | } |
| 1683 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1684 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1685 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1686 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1687 | MockRead read_failure(SYNCHRONOUS, |
| 1688 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1689 | "Connection: Keep-Alive\r\n" |
| 1690 | "Content-Length: 6\r\n\r\n" |
| 1691 | "Pickle"); |
| 1692 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1693 | } |
| 1694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1695 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1696 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1697 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1698 | } |
| 1699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1700 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1701 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1702 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1703 | } |
| 1704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1705 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1706 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1707 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1708 | } |
| 1709 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1710 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1711 | MockRead read_failure(ASYNC, OK); // EOF |
| 1712 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1713 | } |
| 1714 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1715 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1716 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1717 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1718 | MockRead read_failure(SYNCHRONOUS, |
| 1719 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1720 | "Connection: Keep-Alive\r\n" |
| 1721 | "Content-Length: 6\r\n\r\n" |
| 1722 | "Pickle"); |
| 1723 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1724 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1725 | } |
| 1726 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1727 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1728 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1729 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1730 | } |
| 1731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1732 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1733 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1734 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1735 | } |
| 1736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1737 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1738 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1739 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1740 | } |
| 1741 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1742 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1743 | MockRead read_failure(ASYNC, OK); // EOF |
| 1744 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1745 | } |
| 1746 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1747 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1748 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1750 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1754 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1755 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1756 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1757 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1758 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1759 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1760 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1761 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1764 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1765 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1766 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1768 | |
| 1769 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1770 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1771 | |
| 1772 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1773 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1774 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | // What do various browsers do when the server closes a non-keepalive |
| 1778 | // connection without sending any response header or body? |
| 1779 | // |
| 1780 | // IE7: error page |
| 1781 | // Safari 3.1.2 (Windows): error page |
| 1782 | // Firefox 3.0.1: blank page |
| 1783 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1784 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1785 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1786 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1787 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1788 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1789 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1790 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1792 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1793 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1794 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1795 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1796 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1797 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1798 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1799 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1800 | // destructor in such situations. |
| 1801 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1802 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1803 | HttpRequestInfo request; |
| 1804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1805 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1808 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1809 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1810 | |
| 1811 | MockRead data_reads[] = { |
| 1812 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1813 | MockRead("Connection: keep-alive\r\n"), |
| 1814 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1815 | MockRead("hello"), |
| 1816 | MockRead(SYNCHRONOUS, 0), |
| 1817 | }; |
| 1818 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1819 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1820 | |
| 1821 | TestCompletionCallback callback; |
| 1822 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1823 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1825 | |
| 1826 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1828 | |
| 1829 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1830 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1831 | if (rv == ERR_IO_PENDING) |
| 1832 | rv = callback.WaitForResult(); |
| 1833 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1834 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1835 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1836 | |
| 1837 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1838 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1839 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1840 | } |
| 1841 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1842 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1843 | HttpRequestInfo request; |
| 1844 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1845 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1848 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1850 | |
| 1851 | MockRead data_reads[] = { |
| 1852 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1853 | MockRead("Connection: keep-alive\r\n"), |
| 1854 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1855 | MockRead(SYNCHRONOUS, 0), |
| 1856 | }; |
| 1857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1859 | |
| 1860 | TestCompletionCallback callback; |
| 1861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1862 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | |
| 1865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1867 | |
| 1868 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1869 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1870 | if (rv == ERR_IO_PENDING) |
| 1871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1872 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1873 | |
| 1874 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1875 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1876 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1877 | } |
| 1878 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1879 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1880 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1881 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1882 | HttpRequestInfo request; |
| 1883 | request.method = "GET"; |
| 1884 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1885 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1886 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1887 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1889 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1890 | const char* request_data = |
| 1891 | "GET / HTTP/1.1\r\n" |
| 1892 | "Host: www.foo.com\r\n" |
| 1893 | "Connection: keep-alive\r\n\r\n"; |
| 1894 | MockWrite data_writes[] = { |
| 1895 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1896 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1897 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1898 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1899 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1900 | }; |
| 1901 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1902 | // Note that because all these reads happen in the same |
| 1903 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1904 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1905 | MockRead data_reads[] = { |
| 1906 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1907 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1908 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1909 | MockRead(ASYNC, 7, |
| 1910 | "HTTP/1.1 302 Found\r\n" |
| 1911 | "Content-Length: 0\r\n\r\n"), |
| 1912 | MockRead(ASYNC, 9, |
| 1913 | "HTTP/1.1 302 Found\r\n" |
| 1914 | "Content-Length: 5\r\n\r\n" |
| 1915 | "hello"), |
| 1916 | MockRead(ASYNC, 11, |
| 1917 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1918 | "Content-Length: 0\r\n\r\n"), |
| 1919 | MockRead(ASYNC, 13, |
| 1920 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1921 | "Content-Length: 5\r\n\r\n" |
| 1922 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1923 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1924 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1925 | // the set_busy_before_sync_reads(true) call, while the |
| 1926 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1927 | // reuseable. See http://crbug.com/544255. |
| 1928 | MockRead(ASYNC, 15, |
| 1929 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1930 | "Content-Length: 5\r\n\r\n"), |
| 1931 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1932 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1933 | MockRead(ASYNC, 18, |
| 1934 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1935 | "Content-Length: 5\r\n\r\n" |
| 1936 | "he"), |
| 1937 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1938 | |
| 1939 | // The body of the final request is actually read. |
| 1940 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1941 | MockRead(ASYNC, 22, "hello"), |
| 1942 | }; |
| 1943 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1944 | arraysize(data_writes)); |
| 1945 | data.set_busy_before_sync_reads(true); |
| 1946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1947 | |
| 1948 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1949 | std::string response_lines[kNumUnreadBodies]; |
| 1950 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1951 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1952 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1953 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1955 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1956 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1958 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1959 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1960 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1961 | LoadTimingInfo load_timing_info; |
| 1962 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1963 | if (i == 0) { |
| 1964 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1965 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1966 | } else { |
| 1967 | TestLoadTimingReused(load_timing_info); |
| 1968 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1969 | } |
| 1970 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1971 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1972 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1973 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1974 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1975 | response_lines[i] = response->headers->GetStatusLine(); |
| 1976 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1977 | // Delete the transaction without reading the response bodies. Then spin |
| 1978 | // the message loop, so the response bodies are drained. |
| 1979 | trans.reset(); |
| 1980 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1981 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1982 | |
| 1983 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1984 | "HTTP/1.1 204 No Content", |
| 1985 | "HTTP/1.1 205 Reset Content", |
| 1986 | "HTTP/1.1 304 Not Modified", |
| 1987 | "HTTP/1.1 302 Found", |
| 1988 | "HTTP/1.1 302 Found", |
| 1989 | "HTTP/1.1 301 Moved Permanently", |
| 1990 | "HTTP/1.1 301 Moved Permanently", |
| 1991 | "HTTP/1.1 200 Hunky-Dory", |
| 1992 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1993 | }; |
| 1994 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1995 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1996 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1997 | |
| 1998 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1999 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2001 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2004 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2005 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2006 | ASSERT_TRUE(response); |
| 2007 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2008 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2009 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2010 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2011 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2012 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2013 | } |
| 2014 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2015 | // Sockets that receive extra data after a response is complete should not be |
| 2016 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2017 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2019 | MockWrite data_writes1[] = { |
| 2020 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2021 | "Host: www.borked.com\r\n" |
| 2022 | "Connection: keep-alive\r\n\r\n"), |
| 2023 | }; |
| 2024 | |
| 2025 | MockRead data_reads1[] = { |
| 2026 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2027 | "Connection: keep-alive\r\n" |
| 2028 | "Content-Length: 22\r\n\r\n" |
| 2029 | "This server is borked."), |
| 2030 | }; |
| 2031 | |
| 2032 | MockWrite data_writes2[] = { |
| 2033 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2034 | "Host: www.borked.com\r\n" |
| 2035 | "Connection: keep-alive\r\n\r\n"), |
| 2036 | }; |
| 2037 | |
| 2038 | MockRead data_reads2[] = { |
| 2039 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2040 | "Content-Length: 3\r\n\r\n" |
| 2041 | "foo"), |
| 2042 | }; |
| 2043 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2044 | data_writes1, arraysize(data_writes1)); |
| 2045 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2046 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2047 | data_writes2, arraysize(data_writes2)); |
| 2048 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2049 | |
| 2050 | TestCompletionCallback callback; |
| 2051 | HttpRequestInfo request1; |
| 2052 | request1.method = "HEAD"; |
| 2053 | request1.url = GURL("http://www.borked.com/"); |
| 2054 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2055 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2056 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2057 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2058 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2059 | |
| 2060 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2061 | ASSERT_TRUE(response1); |
| 2062 | ASSERT_TRUE(response1->headers); |
| 2063 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2064 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2065 | |
| 2066 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2067 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2068 | EXPECT_EQ("", response_data1); |
| 2069 | // Deleting the transaction attempts to release the socket back into the |
| 2070 | // socket pool. |
| 2071 | trans1.reset(); |
| 2072 | |
| 2073 | HttpRequestInfo request2; |
| 2074 | request2.method = "GET"; |
| 2075 | request2.url = GURL("http://www.borked.com/foo"); |
| 2076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2077 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2079 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2080 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2081 | |
| 2082 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2083 | ASSERT_TRUE(response2); |
| 2084 | ASSERT_TRUE(response2->headers); |
| 2085 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2086 | |
| 2087 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2088 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2089 | EXPECT_EQ("foo", response_data2); |
| 2090 | } |
| 2091 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2092 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2094 | MockWrite data_writes1[] = { |
| 2095 | MockWrite("GET / HTTP/1.1\r\n" |
| 2096 | "Host: www.borked.com\r\n" |
| 2097 | "Connection: keep-alive\r\n\r\n"), |
| 2098 | }; |
| 2099 | |
| 2100 | MockRead data_reads1[] = { |
| 2101 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2102 | "Connection: keep-alive\r\n" |
| 2103 | "Content-Length: 22\r\n\r\n" |
| 2104 | "This server is borked." |
| 2105 | "Bonus data!"), |
| 2106 | }; |
| 2107 | |
| 2108 | MockWrite data_writes2[] = { |
| 2109 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2110 | "Host: www.borked.com\r\n" |
| 2111 | "Connection: keep-alive\r\n\r\n"), |
| 2112 | }; |
| 2113 | |
| 2114 | MockRead data_reads2[] = { |
| 2115 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2116 | "Content-Length: 3\r\n\r\n" |
| 2117 | "foo"), |
| 2118 | }; |
| 2119 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2120 | data_writes1, arraysize(data_writes1)); |
| 2121 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2122 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2123 | data_writes2, arraysize(data_writes2)); |
| 2124 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2125 | |
| 2126 | TestCompletionCallback callback; |
| 2127 | HttpRequestInfo request1; |
| 2128 | request1.method = "GET"; |
| 2129 | request1.url = GURL("http://www.borked.com/"); |
| 2130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2131 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2132 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2133 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2134 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2135 | |
| 2136 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2137 | ASSERT_TRUE(response1); |
| 2138 | ASSERT_TRUE(response1->headers); |
| 2139 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2140 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2141 | |
| 2142 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2143 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2144 | EXPECT_EQ("This server is borked.", response_data1); |
| 2145 | // Deleting the transaction attempts to release the socket back into the |
| 2146 | // socket pool. |
| 2147 | trans1.reset(); |
| 2148 | |
| 2149 | HttpRequestInfo request2; |
| 2150 | request2.method = "GET"; |
| 2151 | request2.url = GURL("http://www.borked.com/foo"); |
| 2152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2153 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2154 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2155 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2157 | |
| 2158 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2159 | ASSERT_TRUE(response2); |
| 2160 | ASSERT_TRUE(response2->headers); |
| 2161 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2162 | |
| 2163 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2164 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2165 | EXPECT_EQ("foo", response_data2); |
| 2166 | } |
| 2167 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2168 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2170 | MockWrite data_writes1[] = { |
| 2171 | MockWrite("GET / HTTP/1.1\r\n" |
| 2172 | "Host: www.borked.com\r\n" |
| 2173 | "Connection: keep-alive\r\n\r\n"), |
| 2174 | }; |
| 2175 | |
| 2176 | MockRead data_reads1[] = { |
| 2177 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2178 | "Connection: keep-alive\r\n" |
| 2179 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2180 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2181 | MockRead("0\r\n\r\nBonus data!"), |
| 2182 | }; |
| 2183 | |
| 2184 | MockWrite data_writes2[] = { |
| 2185 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2186 | "Host: www.borked.com\r\n" |
| 2187 | "Connection: keep-alive\r\n\r\n"), |
| 2188 | }; |
| 2189 | |
| 2190 | MockRead data_reads2[] = { |
| 2191 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2192 | "Content-Length: 3\r\n\r\n" |
| 2193 | "foo"), |
| 2194 | }; |
| 2195 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2196 | data_writes1, arraysize(data_writes1)); |
| 2197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2198 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2199 | data_writes2, arraysize(data_writes2)); |
| 2200 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2201 | |
| 2202 | TestCompletionCallback callback; |
| 2203 | HttpRequestInfo request1; |
| 2204 | request1.method = "GET"; |
| 2205 | request1.url = GURL("http://www.borked.com/"); |
| 2206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2207 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2209 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2210 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2211 | |
| 2212 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2213 | ASSERT_TRUE(response1); |
| 2214 | ASSERT_TRUE(response1->headers); |
| 2215 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2216 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2217 | |
| 2218 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2219 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2220 | EXPECT_EQ("This server is borked.", response_data1); |
| 2221 | // Deleting the transaction attempts to release the socket back into the |
| 2222 | // socket pool. |
| 2223 | trans1.reset(); |
| 2224 | |
| 2225 | HttpRequestInfo request2; |
| 2226 | request2.method = "GET"; |
| 2227 | request2.url = GURL("http://www.borked.com/foo"); |
| 2228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2229 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2231 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2232 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2233 | |
| 2234 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2235 | ASSERT_TRUE(response2); |
| 2236 | ASSERT_TRUE(response2->headers); |
| 2237 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2238 | |
| 2239 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2240 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2241 | EXPECT_EQ("foo", response_data2); |
| 2242 | } |
| 2243 | |
| 2244 | // This is a little different from the others - it tests the case that the |
| 2245 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2246 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2247 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2248 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2250 | MockWrite data_writes1[] = { |
| 2251 | MockWrite("GET / HTTP/1.1\r\n" |
| 2252 | "Host: www.borked.com\r\n" |
| 2253 | "Connection: keep-alive\r\n\r\n"), |
| 2254 | }; |
| 2255 | |
| 2256 | MockRead data_reads1[] = { |
| 2257 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2258 | "Connection: keep-alive\r\n" |
| 2259 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2260 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2261 | MockRead("0\r\n\r\nBonus data!"), |
| 2262 | }; |
| 2263 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2264 | data_writes1, arraysize(data_writes1)); |
| 2265 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2266 | |
| 2267 | TestCompletionCallback callback; |
| 2268 | HttpRequestInfo request1; |
| 2269 | request1.method = "GET"; |
| 2270 | request1.url = GURL("http://www.borked.com/"); |
| 2271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2272 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2273 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2274 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2275 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2276 | |
| 2277 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2278 | ASSERT_TRUE(response1); |
| 2279 | ASSERT_TRUE(response1->headers); |
| 2280 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2281 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2282 | |
| 2283 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2284 | // response body. |
| 2285 | trans1.reset(); |
| 2286 | |
| 2287 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2288 | // socket can't be reused, rather than returning it to the socket pool. |
| 2289 | base::RunLoop().RunUntilIdle(); |
| 2290 | |
| 2291 | // There should be no idle sockets in the pool. |
| 2292 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2293 | } |
| 2294 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2295 | // Test the request-challenge-retry sequence for basic auth. |
| 2296 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2297 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2298 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2299 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2300 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2301 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2302 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2303 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2306 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2307 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2308 | MockWrite( |
| 2309 | "GET / HTTP/1.1\r\n" |
| 2310 | "Host: www.example.org\r\n" |
| 2311 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2312 | }; |
| 2313 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2314 | MockRead data_reads1[] = { |
| 2315 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2316 | // Give a couple authenticate options (only the middle one is actually |
| 2317 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2318 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2319 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2320 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2321 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2322 | // Large content-length -- won't matter, as connection will be reset. |
| 2323 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2324 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2325 | }; |
| 2326 | |
| 2327 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2328 | // be issuing -- the final header line contains the credentials. |
| 2329 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2330 | MockWrite( |
| 2331 | "GET / HTTP/1.1\r\n" |
| 2332 | "Host: www.example.org\r\n" |
| 2333 | "Connection: keep-alive\r\n" |
| 2334 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | // Lastly, the server responds with the actual content. |
| 2338 | MockRead data_reads2[] = { |
| 2339 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2340 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2341 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2342 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2343 | }; |
| 2344 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2345 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2346 | data_writes1, arraysize(data_writes1)); |
| 2347 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2348 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2349 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2350 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2352 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2354 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2356 | |
| 2357 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2358 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2359 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2360 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2361 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2362 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2363 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2364 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2365 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2366 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2367 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2369 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2370 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2371 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2373 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2375 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2377 | |
| 2378 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2380 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2381 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2382 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2383 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2384 | // The load timing after restart should have a new socket ID, and times after |
| 2385 | // those of the first load timing. |
| 2386 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2387 | load_timing_info2.connect_timing.connect_start); |
| 2388 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2389 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2390 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2391 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2392 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2393 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2395 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2396 | ASSERT_TRUE(response); |
| 2397 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2398 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2399 | } |
| 2400 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2401 | // Test the request-challenge-retry sequence for basic auth. |
| 2402 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2403 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2404 | HttpRequestInfo request; |
| 2405 | request.method = "GET"; |
| 2406 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2407 | |
| 2408 | TestNetLog log; |
| 2409 | MockHostResolver* resolver = new MockHostResolver(); |
| 2410 | session_deps_.net_log = &log; |
| 2411 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2412 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2414 | |
| 2415 | resolver->rules()->ClearRules(); |
| 2416 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2417 | |
| 2418 | MockWrite data_writes1[] = { |
| 2419 | MockWrite("GET / HTTP/1.1\r\n" |
| 2420 | "Host: www.example.org\r\n" |
| 2421 | "Connection: keep-alive\r\n\r\n"), |
| 2422 | }; |
| 2423 | |
| 2424 | MockRead data_reads1[] = { |
| 2425 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2426 | // Give a couple authenticate options (only the middle one is actually |
| 2427 | // supported). |
| 2428 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2429 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2430 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2432 | // Large content-length -- won't matter, as connection will be reset. |
| 2433 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2434 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2435 | }; |
| 2436 | |
| 2437 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2438 | // be issuing -- the final header line contains the credentials. |
| 2439 | MockWrite data_writes2[] = { |
| 2440 | MockWrite("GET / HTTP/1.1\r\n" |
| 2441 | "Host: www.example.org\r\n" |
| 2442 | "Connection: keep-alive\r\n" |
| 2443 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2444 | }; |
| 2445 | |
| 2446 | // Lastly, the server responds with the actual content. |
| 2447 | MockRead data_reads2[] = { |
| 2448 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2449 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2450 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2451 | }; |
| 2452 | |
| 2453 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2454 | data_writes1, arraysize(data_writes1)); |
| 2455 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2456 | data_writes2, arraysize(data_writes2)); |
| 2457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2459 | |
| 2460 | TestCompletionCallback callback1; |
| 2461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2462 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2463 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2464 | |
| 2465 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2466 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2467 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2468 | |
| 2469 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2470 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2471 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2472 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2475 | ASSERT_TRUE(response); |
| 2476 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2477 | |
| 2478 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2479 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2480 | ASSERT_FALSE(endpoint.address().empty()); |
| 2481 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2482 | |
| 2483 | resolver->rules()->ClearRules(); |
| 2484 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2485 | |
| 2486 | TestCompletionCallback callback2; |
| 2487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2488 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2489 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2490 | |
| 2491 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2492 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2493 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2494 | // The load timing after restart should have a new socket ID, and times after |
| 2495 | // those of the first load timing. |
| 2496 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2497 | load_timing_info2.connect_timing.connect_start); |
| 2498 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2499 | |
| 2500 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2501 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2502 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2503 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2505 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2506 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2507 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2508 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2510 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2511 | ASSERT_FALSE(endpoint.address().empty()); |
| 2512 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2513 | } |
| 2514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2515 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2516 | HttpRequestInfo request; |
| 2517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2518 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2519 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2523 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2524 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2525 | MockWrite( |
| 2526 | "GET / HTTP/1.1\r\n" |
| 2527 | "Host: www.example.org\r\n" |
| 2528 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2529 | }; |
| 2530 | |
| 2531 | MockRead data_reads[] = { |
| 2532 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2533 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2534 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2535 | // Large content-length -- won't matter, as connection will be reset. |
| 2536 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2537 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2538 | }; |
| 2539 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2540 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2541 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2543 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2545 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2547 | |
| 2548 | rv = callback.WaitForResult(); |
| 2549 | EXPECT_EQ(0, rv); |
| 2550 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2551 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2552 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2553 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2556 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2557 | ASSERT_TRUE(response); |
| 2558 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2559 | } |
| 2560 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2561 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2562 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2563 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2564 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2565 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2566 | // reused. See http://crbug.com/544255. |
| 2567 | for (int i = 0; i < 2; ++i) { |
| 2568 | HttpRequestInfo request; |
| 2569 | request.method = "GET"; |
| 2570 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2571 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2572 | TestNetLog log; |
| 2573 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2575 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2576 | MockWrite data_writes[] = { |
| 2577 | MockWrite(ASYNC, 0, |
| 2578 | "GET / HTTP/1.1\r\n" |
| 2579 | "Host: www.example.org\r\n" |
| 2580 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2582 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2583 | // be issuing -- the final header line contains the credentials. |
| 2584 | MockWrite(ASYNC, 6, |
| 2585 | "GET / HTTP/1.1\r\n" |
| 2586 | "Host: www.example.org\r\n" |
| 2587 | "Connection: keep-alive\r\n" |
| 2588 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2589 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2590 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2591 | MockRead data_reads[] = { |
| 2592 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2593 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2594 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2595 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2596 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2597 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2598 | // Lastly, the server responds with the actual content. |
| 2599 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2600 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2601 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2602 | MockRead(ASYNC, 10, "Hello"), |
| 2603 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2604 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2605 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2606 | arraysize(data_writes)); |
| 2607 | data.set_busy_before_sync_reads(true); |
| 2608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2609 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2610 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2613 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2614 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2615 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2616 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2617 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2618 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2620 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2621 | ASSERT_TRUE(response); |
| 2622 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2623 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2624 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2626 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2627 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2628 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2629 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2630 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2631 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2632 | TestLoadTimingReused(load_timing_info2); |
| 2633 | // The load timing after restart should have the same socket ID, and times |
| 2634 | // those of the first load timing. |
| 2635 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2636 | load_timing_info2.send_start); |
| 2637 | 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] | 2638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2639 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2640 | ASSERT_TRUE(response); |
| 2641 | EXPECT_FALSE(response->auth_challenge); |
| 2642 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2643 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2644 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2645 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2646 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2647 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2648 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2649 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2650 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2651 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2655 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2656 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2657 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2658 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2659 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2662 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2663 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2664 | MockWrite("GET / HTTP/1.1\r\n" |
| 2665 | "Host: www.example.org\r\n" |
| 2666 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2668 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2669 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | MockWrite("GET / HTTP/1.1\r\n" |
| 2671 | "Host: www.example.org\r\n" |
| 2672 | "Connection: keep-alive\r\n" |
| 2673 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | }; |
| 2675 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2676 | MockRead data_reads1[] = { |
| 2677 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2678 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2679 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | |
| 2681 | // Lastly, the server responds with the actual content. |
| 2682 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2684 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2685 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2686 | }; |
| 2687 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2688 | // An incorrect reconnect would cause this to be read. |
| 2689 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2690 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2691 | }; |
| 2692 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2693 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2694 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2695 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2696 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2698 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2700 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2703 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2705 | |
| 2706 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2707 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2709 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2710 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2711 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2713 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2717 | |
| 2718 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2719 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2721 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2722 | ASSERT_TRUE(response); |
| 2723 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2724 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2728 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2729 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2730 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2732 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2735 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2736 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | MockWrite("GET / HTTP/1.1\r\n" |
| 2738 | "Host: www.example.org\r\n" |
| 2739 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2742 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2743 | MockWrite("GET / HTTP/1.1\r\n" |
| 2744 | "Host: www.example.org\r\n" |
| 2745 | "Connection: keep-alive\r\n" |
| 2746 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | }; |
| 2748 | |
| 2749 | // Respond with 5 kb of response body. |
| 2750 | std::string large_body_string("Unauthorized"); |
| 2751 | large_body_string.append(5 * 1024, ' '); |
| 2752 | large_body_string.append("\r\n"); |
| 2753 | |
| 2754 | MockRead data_reads1[] = { |
| 2755 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2756 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2757 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2758 | // 5134 = 12 + 5 * 1024 + 2 |
| 2759 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2760 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | |
| 2762 | // Lastly, the server responds with the actual content. |
| 2763 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2764 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2765 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2766 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2767 | }; |
| 2768 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2769 | // An incorrect reconnect would cause this to be read. |
| 2770 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2771 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2772 | }; |
| 2773 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2774 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2775 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2776 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2777 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2778 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2779 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2781 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2784 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
| 2787 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2788 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2790 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2791 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2792 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2794 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2798 | |
| 2799 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2800 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2803 | ASSERT_TRUE(response); |
| 2804 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2805 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2809 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2810 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2811 | HttpRequestInfo request; |
| 2812 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2813 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2816 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2817 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2818 | MockWrite( |
| 2819 | "GET / HTTP/1.1\r\n" |
| 2820 | "Host: www.example.org\r\n" |
| 2821 | "Connection: keep-alive\r\n\r\n"), |
| 2822 | // This simulates the seemingly successful write to a closed connection |
| 2823 | // if the bug is not fixed. |
| 2824 | MockWrite( |
| 2825 | "GET / HTTP/1.1\r\n" |
| 2826 | "Host: www.example.org\r\n" |
| 2827 | "Connection: keep-alive\r\n" |
| 2828 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2829 | }; |
| 2830 | |
| 2831 | MockRead data_reads1[] = { |
| 2832 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2833 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2834 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2835 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2836 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2837 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2838 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2839 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2840 | }; |
| 2841 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2842 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2843 | // be issuing -- the final header line contains the credentials. |
| 2844 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2845 | MockWrite( |
| 2846 | "GET / HTTP/1.1\r\n" |
| 2847 | "Host: www.example.org\r\n" |
| 2848 | "Connection: keep-alive\r\n" |
| 2849 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2850 | }; |
| 2851 | |
| 2852 | // Lastly, the server responds with the actual content. |
| 2853 | MockRead data_reads2[] = { |
| 2854 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2855 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2856 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2857 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2858 | }; |
| 2859 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2860 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2861 | data_writes1, arraysize(data_writes1)); |
| 2862 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2863 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2864 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2865 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2867 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2870 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2872 | |
| 2873 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2874 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2876 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2877 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2878 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2880 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2882 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2884 | |
| 2885 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2888 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2889 | ASSERT_TRUE(response); |
| 2890 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2891 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2892 | } |
| 2893 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2894 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2895 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2896 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2897 | HttpRequestInfo request; |
| 2898 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2899 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2900 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2901 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2902 | |
| 2903 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2904 | session_deps_.proxy_service = |
| 2905 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2906 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2907 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2909 | |
| 2910 | // Since we have proxy, should try to establish tunnel. |
| 2911 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2913 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2914 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2915 | }; |
| 2916 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2917 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2918 | // connection. |
| 2919 | MockRead data_reads1[] = { |
| 2920 | // No credentials. |
| 2921 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2922 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2923 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2924 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2925 | // Since the first connection couldn't be reused, need to establish another |
| 2926 | // once given credentials. |
| 2927 | MockWrite data_writes2[] = { |
| 2928 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2929 | // be issuing -- the final header line contains the credentials. |
| 2930 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2931 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2932 | "Proxy-Connection: keep-alive\r\n" |
| 2933 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2934 | |
| 2935 | MockWrite("GET / HTTP/1.1\r\n" |
| 2936 | "Host: www.example.org\r\n" |
| 2937 | "Connection: keep-alive\r\n\r\n"), |
| 2938 | }; |
| 2939 | |
| 2940 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2941 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2942 | |
| 2943 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2944 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2945 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2946 | MockRead(SYNCHRONOUS, "hello"), |
| 2947 | }; |
| 2948 | |
| 2949 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2950 | data_writes1, arraysize(data_writes1)); |
| 2951 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2952 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2953 | data_writes2, arraysize(data_writes2)); |
| 2954 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2955 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2957 | |
| 2958 | TestCompletionCallback callback1; |
| 2959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2960 | std::unique_ptr<HttpNetworkTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2962 | |
| 2963 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2965 | |
| 2966 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2967 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2968 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2969 | log.GetEntries(&entries); |
| 2970 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2971 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2972 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2973 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2974 | entries, pos, |
| 2975 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2976 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2977 | |
| 2978 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2979 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2980 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2981 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2982 | EXPECT_EQ(407, response->headers->response_code()); |
| 2983 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2984 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2985 | |
| 2986 | LoadTimingInfo load_timing_info; |
| 2987 | // CONNECT requests and responses are handled at the connect job level, so |
| 2988 | // the transaction does not yet have a connection. |
| 2989 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2990 | |
| 2991 | TestCompletionCallback callback2; |
| 2992 | |
| 2993 | rv = |
| 2994 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2996 | |
| 2997 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2998 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2999 | |
| 3000 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3001 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3002 | |
| 3003 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3004 | EXPECT_EQ(200, response->headers->response_code()); |
| 3005 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3006 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3007 | |
| 3008 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3009 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3010 | |
| 3011 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3012 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3013 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3014 | |
| 3015 | trans.reset(); |
| 3016 | session->CloseAllConnections(); |
| 3017 | } |
| 3018 | |
| 3019 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3020 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3021 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3022 | HttpRequestInfo request; |
| 3023 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3024 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3025 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3026 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3027 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3028 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3029 | session_deps_.proxy_service = |
| 3030 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3031 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3032 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3034 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3035 | // Since we have proxy, should try to establish tunnel. |
| 3036 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3037 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3038 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3039 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3040 | }; |
| 3041 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3042 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3043 | // connection. |
| 3044 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3045 | // No credentials. |
| 3046 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3047 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3048 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3049 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3050 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3051 | MockWrite data_writes2[] = { |
| 3052 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3053 | // be issuing -- the final header line contains the credentials. |
| 3054 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3055 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3056 | "Proxy-Connection: keep-alive\r\n" |
| 3057 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3058 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3059 | MockWrite("GET / HTTP/1.1\r\n" |
| 3060 | "Host: www.example.org\r\n" |
| 3061 | "Connection: keep-alive\r\n\r\n"), |
| 3062 | }; |
| 3063 | |
| 3064 | MockRead data_reads2[] = { |
| 3065 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3066 | |
| 3067 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3069 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3070 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3071 | }; |
| 3072 | |
| 3073 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3074 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3075 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3076 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3077 | data_writes2, arraysize(data_writes2)); |
| 3078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3079 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3082 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3084 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3085 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3087 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3089 | |
| 3090 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3091 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3092 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3093 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3094 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3095 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3096 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3097 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3098 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3099 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3100 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3101 | |
| 3102 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3103 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3104 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3105 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3106 | EXPECT_EQ(407, response->headers->response_code()); |
| 3107 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3108 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3109 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3110 | LoadTimingInfo load_timing_info; |
| 3111 | // CONNECT requests and responses are handled at the connect job level, so |
| 3112 | // the transaction does not yet have a connection. |
| 3113 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3115 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3117 | rv = trans->RestartWithAuth( |
| 3118 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3120 | |
| 3121 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3122 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3123 | |
| 3124 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3125 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3126 | |
| 3127 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3128 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3129 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3130 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3131 | |
| 3132 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3133 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3134 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3135 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3136 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3137 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3138 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3139 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3140 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3141 | } |
| 3142 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3143 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3144 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3145 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3146 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3147 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3148 | // reused. See http://crbug.com/544255. |
| 3149 | for (int i = 0; i < 2; ++i) { |
| 3150 | HttpRequestInfo request; |
| 3151 | request.method = "GET"; |
| 3152 | request.url = GURL("https://www.example.org/"); |
| 3153 | // Ensure that proxy authentication is attempted even |
| 3154 | // when the no authentication data flag is set. |
| 3155 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3156 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3157 | // Configure against proxy server "myproxy:70". |
| 3158 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3159 | BoundTestNetLog log; |
| 3160 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3163 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3164 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3165 | // Since we have proxy, should try to establish tunnel. |
| 3166 | MockWrite data_writes1[] = { |
| 3167 | MockWrite(ASYNC, 0, |
| 3168 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3169 | "Host: www.example.org:443\r\n" |
| 3170 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3172 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3173 | // be issuing -- the final header line contains the credentials. |
| 3174 | MockWrite(ASYNC, 3, |
| 3175 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3176 | "Host: www.example.org:443\r\n" |
| 3177 | "Proxy-Connection: keep-alive\r\n" |
| 3178 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3179 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3180 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3181 | // The proxy responds to the connect with a 407, using a persistent |
| 3182 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3183 | MockRead data_reads1[] = { |
| 3184 | // No credentials. |
| 3185 | MockRead(ASYNC, 1, |
| 3186 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3187 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3188 | "Proxy-Connection: keep-alive\r\n" |
| 3189 | "Content-Length: 10\r\n\r\n"), |
| 3190 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3191 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3192 | // Wrong credentials (wrong password). |
| 3193 | MockRead(ASYNC, 4, |
| 3194 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3195 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3196 | "Proxy-Connection: keep-alive\r\n" |
| 3197 | "Content-Length: 10\r\n\r\n"), |
| 3198 | // No response body because the test stops reading here. |
| 3199 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3200 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3201 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3202 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3203 | arraysize(data_writes1)); |
| 3204 | data1.set_busy_before_sync_reads(true); |
| 3205 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3206 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3207 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3209 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3210 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3211 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3212 | TestNetLogEntry::List entries; |
| 3213 | log.GetEntries(&entries); |
| 3214 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3215 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3216 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3217 | ExpectLogContainsSomewhere( |
| 3218 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3219 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3220 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3223 | ASSERT_TRUE(response); |
| 3224 | ASSERT_TRUE(response->headers); |
| 3225 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3226 | EXPECT_EQ(407, response->headers->response_code()); |
| 3227 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3228 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3229 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3230 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3231 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3232 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3233 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3234 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3235 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3236 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3238 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3239 | ASSERT_TRUE(response); |
| 3240 | ASSERT_TRUE(response->headers); |
| 3241 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3242 | EXPECT_EQ(407, response->headers->response_code()); |
| 3243 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3244 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3245 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3246 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3247 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3248 | // out of scope. |
| 3249 | session->CloseAllConnections(); |
| 3250 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3254 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3255 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3256 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3257 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3258 | // reused. See http://crbug.com/544255. |
| 3259 | for (int i = 0; i < 2; ++i) { |
| 3260 | HttpRequestInfo request; |
| 3261 | request.method = "GET"; |
| 3262 | request.url = GURL("https://www.example.org/"); |
| 3263 | // Ensure that proxy authentication is attempted even |
| 3264 | // when the no authentication data flag is set. |
| 3265 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3266 | |
| 3267 | // Configure against proxy server "myproxy:70". |
| 3268 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3269 | BoundTestNetLog log; |
| 3270 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3273 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3274 | |
| 3275 | // Since we have proxy, should try to establish tunnel. |
| 3276 | MockWrite data_writes1[] = { |
| 3277 | MockWrite(ASYNC, 0, |
| 3278 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3279 | "Host: www.example.org:443\r\n" |
| 3280 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3282 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3283 | // be issuing -- the final header line contains the credentials. |
| 3284 | MockWrite(ASYNC, 3, |
| 3285 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3286 | "Host: www.example.org:443\r\n" |
| 3287 | "Proxy-Connection: keep-alive\r\n" |
| 3288 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3289 | }; |
| 3290 | |
| 3291 | // The proxy responds to the connect with a 407, using a persistent |
| 3292 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3293 | MockRead data_reads1[] = { |
| 3294 | // No credentials. |
| 3295 | MockRead(ASYNC, 1, |
| 3296 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3297 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3298 | "Content-Length: 10\r\n\r\n"), |
| 3299 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3300 | |
| 3301 | // Wrong credentials (wrong password). |
| 3302 | MockRead(ASYNC, 4, |
| 3303 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3304 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3305 | "Content-Length: 10\r\n\r\n"), |
| 3306 | // No response body because the test stops reading here. |
| 3307 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3308 | }; |
| 3309 | |
| 3310 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3311 | arraysize(data_writes1)); |
| 3312 | data1.set_busy_before_sync_reads(true); |
| 3313 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3314 | |
| 3315 | TestCompletionCallback callback1; |
| 3316 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3317 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3318 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3319 | |
| 3320 | TestNetLogEntry::List entries; |
| 3321 | log.GetEntries(&entries); |
| 3322 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3323 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3324 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3325 | ExpectLogContainsSomewhere( |
| 3326 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3327 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3328 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3330 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3331 | ASSERT_TRUE(response); |
| 3332 | ASSERT_TRUE(response->headers); |
| 3333 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3334 | EXPECT_EQ(407, response->headers->response_code()); |
| 3335 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3336 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3337 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3338 | |
| 3339 | TestCompletionCallback callback2; |
| 3340 | |
| 3341 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3342 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3343 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3344 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3346 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3347 | ASSERT_TRUE(response); |
| 3348 | ASSERT_TRUE(response->headers); |
| 3349 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3350 | EXPECT_EQ(407, response->headers->response_code()); |
| 3351 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3352 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3353 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3354 | |
| 3355 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3356 | // out of scope. |
| 3357 | session->CloseAllConnections(); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3362 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3363 | // the case the server sends extra data on the original socket, so it can't be |
| 3364 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3365 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3366 | HttpRequestInfo request; |
| 3367 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3368 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3369 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3370 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3371 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3372 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3373 | session_deps_.proxy_service = |
| 3374 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3375 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3376 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3378 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3379 | // Since we have proxy, should try to establish tunnel. |
| 3380 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3381 | MockWrite(ASYNC, 0, |
| 3382 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3383 | "Host: www.example.org:443\r\n" |
| 3384 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3385 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3386 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3387 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3388 | // extra data, so the socket cannot be reused. |
| 3389 | MockRead data_reads1[] = { |
| 3390 | // No credentials. |
| 3391 | MockRead(ASYNC, 1, |
| 3392 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3393 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3394 | "Content-Length: 10\r\n\r\n"), |
| 3395 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3396 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3397 | }; |
| 3398 | |
| 3399 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3400 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3401 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3402 | MockWrite(ASYNC, 0, |
| 3403 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3404 | "Host: www.example.org:443\r\n" |
| 3405 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3406 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3407 | |
| 3408 | MockWrite(ASYNC, 2, |
| 3409 | "GET / HTTP/1.1\r\n" |
| 3410 | "Host: www.example.org\r\n" |
| 3411 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3412 | }; |
| 3413 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3414 | MockRead data_reads2[] = { |
| 3415 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3416 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3417 | MockRead(ASYNC, 3, |
| 3418 | "HTTP/1.1 200 OK\r\n" |
| 3419 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3420 | "Content-Length: 5\r\n\r\n"), |
| 3421 | // No response body because the test stops reading here. |
| 3422 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3423 | }; |
| 3424 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3425 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3426 | arraysize(data_writes1)); |
| 3427 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3428 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3429 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3430 | arraysize(data_writes2)); |
| 3431 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3432 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3435 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3437 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3439 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3440 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3441 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3442 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3443 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3444 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3445 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3446 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3447 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3448 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3449 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3450 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3451 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3452 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3453 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3454 | ASSERT_TRUE(response); |
| 3455 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3456 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3457 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3458 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3459 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3460 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3461 | LoadTimingInfo load_timing_info; |
| 3462 | // CONNECT requests and responses are handled at the connect job level, so |
| 3463 | // the transaction does not yet have a connection. |
| 3464 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3466 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3467 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3468 | rv = |
| 3469 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3470 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3471 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3472 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3473 | EXPECT_EQ(200, response->headers->response_code()); |
| 3474 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3475 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3476 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3477 | // The password prompt info should not be set. |
| 3478 | EXPECT_FALSE(response->auth_challenge); |
| 3479 | |
| 3480 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3481 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3482 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3483 | |
| 3484 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3485 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3486 | } |
| 3487 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3488 | // Test the case a proxy closes a socket while the challenge body is being |
| 3489 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3490 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3491 | HttpRequestInfo request; |
| 3492 | request.method = "GET"; |
| 3493 | request.url = GURL("https://www.example.org/"); |
| 3494 | // Ensure that proxy authentication is attempted even |
| 3495 | // when the no authentication data flag is set. |
| 3496 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3497 | |
| 3498 | // Configure against proxy server "myproxy:70". |
| 3499 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3500 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3503 | |
| 3504 | // Since we have proxy, should try to establish tunnel. |
| 3505 | MockWrite data_writes1[] = { |
| 3506 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3507 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3508 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3509 | }; |
| 3510 | |
| 3511 | // The proxy responds to the connect with a 407, using a persistent |
| 3512 | // connection. |
| 3513 | MockRead data_reads1[] = { |
| 3514 | // No credentials. |
| 3515 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3516 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3517 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3518 | // Server hands up in the middle of the body. |
| 3519 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3520 | }; |
| 3521 | |
| 3522 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3523 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3524 | // be issuing -- the final header line contains the credentials. |
| 3525 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3526 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3527 | "Proxy-Connection: keep-alive\r\n" |
| 3528 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3529 | |
| 3530 | MockWrite("GET / HTTP/1.1\r\n" |
| 3531 | "Host: www.example.org\r\n" |
| 3532 | "Connection: keep-alive\r\n\r\n"), |
| 3533 | }; |
| 3534 | |
| 3535 | MockRead data_reads2[] = { |
| 3536 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3537 | |
| 3538 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3539 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3540 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3541 | MockRead(SYNCHRONOUS, "hello"), |
| 3542 | }; |
| 3543 | |
| 3544 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3545 | data_writes1, arraysize(data_writes1)); |
| 3546 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3547 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3548 | data_writes2, arraysize(data_writes2)); |
| 3549 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3550 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3551 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3552 | |
| 3553 | TestCompletionCallback callback; |
| 3554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3556 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3559 | ASSERT_TRUE(response); |
| 3560 | ASSERT_TRUE(response->headers); |
| 3561 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3562 | EXPECT_EQ(407, response->headers->response_code()); |
| 3563 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3564 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3565 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3566 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3568 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3569 | ASSERT_TRUE(response); |
| 3570 | ASSERT_TRUE(response->headers); |
| 3571 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3572 | EXPECT_EQ(200, response->headers->response_code()); |
| 3573 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3574 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3575 | EXPECT_EQ("hello", body); |
| 3576 | } |
| 3577 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3578 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3579 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3580 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3581 | HttpRequestInfo request; |
| 3582 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3583 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3584 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3585 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3586 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3591 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3592 | // Since we have proxy, should try to establish tunnel. |
| 3593 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3594 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3595 | "Host: www.example.org:443\r\n" |
| 3596 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3597 | }; |
| 3598 | |
| 3599 | // The proxy responds to the connect with a 407. |
| 3600 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3601 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3602 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3603 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3605 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3606 | }; |
| 3607 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3609 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3612 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3616 | |
| 3617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3620 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3621 | ASSERT_TRUE(response); |
| 3622 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3623 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3624 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3625 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3626 | |
| 3627 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3628 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3629 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3630 | |
| 3631 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3632 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3633 | } |
| 3634 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3635 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3636 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3637 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3638 | HttpRequestInfo request; |
| 3639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3640 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3641 | |
| 3642 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3643 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3648 | |
| 3649 | // Since we have proxy, should try to establish tunnel. |
| 3650 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3651 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3652 | "Host: www.example.org:443\r\n" |
| 3653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3654 | }; |
| 3655 | |
| 3656 | // The proxy responds to the connect with a 407. |
| 3657 | MockRead data_reads[] = { |
| 3658 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3659 | MockRead("X-Foo: bar\r\n"), |
| 3660 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3661 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3662 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3663 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3664 | }; |
| 3665 | |
| 3666 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3667 | arraysize(data_writes)); |
| 3668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3669 | |
| 3670 | TestCompletionCallback callback; |
| 3671 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3672 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3674 | |
| 3675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3676 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3678 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3679 | ASSERT_TRUE(response); |
| 3680 | ASSERT_TRUE(response->headers); |
| 3681 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3682 | EXPECT_EQ(407, response->headers->response_code()); |
| 3683 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3684 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3685 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3686 | |
| 3687 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3689 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3690 | |
| 3691 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3692 | session->CloseAllConnections(); |
| 3693 | } |
| 3694 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3695 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3696 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3697 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3698 | HttpRequestInfo request; |
| 3699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3701 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3702 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3703 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3705 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3706 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3707 | MockWrite( |
| 3708 | "GET / HTTP/1.1\r\n" |
| 3709 | "Host: www.example.org\r\n" |
| 3710 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3711 | }; |
| 3712 | |
| 3713 | MockRead data_reads1[] = { |
| 3714 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3715 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3716 | // Large content-length -- won't matter, as connection will be reset. |
| 3717 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3718 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3719 | }; |
| 3720 | |
| 3721 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3722 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3723 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3725 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3726 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3727 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3729 | |
| 3730 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3731 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3732 | } |
| 3733 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3734 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3735 | // through a non-authenticating proxy. The request should fail with |
| 3736 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3737 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3738 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3739 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3740 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3741 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3742 | HttpRequestInfo request; |
| 3743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3744 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3745 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3746 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3747 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3748 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3749 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3750 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3751 | // Since we have proxy, should try to establish tunnel. |
| 3752 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3753 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3754 | "Host: www.example.org:443\r\n" |
| 3755 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3756 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3757 | MockWrite("GET / HTTP/1.1\r\n" |
| 3758 | "Host: www.example.org\r\n" |
| 3759 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3760 | }; |
| 3761 | |
| 3762 | MockRead data_reads1[] = { |
| 3763 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3764 | |
| 3765 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3766 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3767 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3769 | }; |
| 3770 | |
| 3771 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3772 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3773 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3774 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3777 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3779 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3781 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3783 | |
| 3784 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3785 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3786 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3787 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3788 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3789 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3790 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3791 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3792 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3793 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3794 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3795 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3796 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3797 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3798 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3799 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3800 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3801 | HttpRequestInfo request; |
| 3802 | request.method = "GET"; |
| 3803 | request.url = GURL("https://www.example.org/"); |
| 3804 | |
| 3805 | // Configure against proxy server "myproxy:70". |
| 3806 | session_deps_.proxy_service = |
| 3807 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3809 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3810 | new HttpAuthHandlerMock::Factory()); |
| 3811 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3812 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3813 | mock_handler->set_allows_default_credentials(true); |
| 3814 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3815 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3816 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3817 | |
| 3818 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3819 | NetLog net_log; |
| 3820 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3821 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3822 | |
| 3823 | // Since we have proxy, should try to establish tunnel. |
| 3824 | MockWrite data_writes1[] = { |
| 3825 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3826 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3827 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3828 | }; |
| 3829 | |
| 3830 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3831 | // connection. |
| 3832 | MockRead data_reads1[] = { |
| 3833 | // No credentials. |
| 3834 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3835 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3836 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3837 | }; |
| 3838 | |
| 3839 | // Since the first connection couldn't be reused, need to establish another |
| 3840 | // once given credentials. |
| 3841 | MockWrite data_writes2[] = { |
| 3842 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3843 | // be issuing -- the final header line contains the credentials. |
| 3844 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3845 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3846 | "Proxy-Connection: keep-alive\r\n" |
| 3847 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3848 | |
| 3849 | MockWrite("GET / HTTP/1.1\r\n" |
| 3850 | "Host: www.example.org\r\n" |
| 3851 | "Connection: keep-alive\r\n\r\n"), |
| 3852 | }; |
| 3853 | |
| 3854 | MockRead data_reads2[] = { |
| 3855 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3856 | |
| 3857 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3858 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3859 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3860 | MockRead(SYNCHRONOUS, "hello"), |
| 3861 | }; |
| 3862 | |
| 3863 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3864 | data_writes1, arraysize(data_writes1)); |
| 3865 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3866 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3867 | data_writes2, arraysize(data_writes2)); |
| 3868 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3869 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3872 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3873 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3874 | |
| 3875 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3876 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3877 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3878 | |
| 3879 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3880 | ASSERT_TRUE(response); |
| 3881 | ASSERT_TRUE(response->headers); |
| 3882 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3883 | EXPECT_EQ(407, response->headers->response_code()); |
| 3884 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3885 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3886 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3887 | |
| 3888 | LoadTimingInfo load_timing_info; |
| 3889 | // CONNECT requests and responses are handled at the connect job level, so |
| 3890 | // the transaction does not yet have a connection. |
| 3891 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3892 | |
| 3893 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3894 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3895 | response = trans->GetResponseInfo(); |
| 3896 | ASSERT_TRUE(response); |
| 3897 | ASSERT_TRUE(response->headers); |
| 3898 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3899 | EXPECT_EQ(200, response->headers->response_code()); |
| 3900 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3901 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3902 | |
| 3903 | // The password prompt info should not be set. |
| 3904 | EXPECT_FALSE(response->auth_challenge); |
| 3905 | |
| 3906 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3907 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3908 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3909 | |
| 3910 | trans.reset(); |
| 3911 | session->CloseAllConnections(); |
| 3912 | } |
| 3913 | |
| 3914 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3915 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3916 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3917 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3918 | HttpRequestInfo request; |
| 3919 | request.method = "GET"; |
| 3920 | request.url = GURL("https://www.example.org/"); |
| 3921 | |
| 3922 | // Configure against proxy server "myproxy:70". |
| 3923 | session_deps_.proxy_service = |
| 3924 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3925 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3926 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3927 | new HttpAuthHandlerMock::Factory()); |
| 3928 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3929 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3930 | mock_handler->set_allows_default_credentials(true); |
| 3931 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3932 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3933 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3934 | |
| 3935 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3936 | NetLog net_log; |
| 3937 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3938 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3939 | |
| 3940 | // Should try to establish tunnel. |
| 3941 | MockWrite data_writes1[] = { |
| 3942 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3943 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3944 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3945 | |
| 3946 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3947 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3948 | "Proxy-Connection: keep-alive\r\n" |
| 3949 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3950 | }; |
| 3951 | |
| 3952 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3953 | // connection. |
| 3954 | MockRead data_reads1[] = { |
| 3955 | // No credentials. |
| 3956 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3957 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3958 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3959 | }; |
| 3960 | |
| 3961 | // Since the first connection was closed, need to establish another once given |
| 3962 | // credentials. |
| 3963 | MockWrite data_writes2[] = { |
| 3964 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3965 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3966 | "Proxy-Connection: keep-alive\r\n" |
| 3967 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3968 | |
| 3969 | MockWrite("GET / HTTP/1.1\r\n" |
| 3970 | "Host: www.example.org\r\n" |
| 3971 | "Connection: keep-alive\r\n\r\n"), |
| 3972 | }; |
| 3973 | |
| 3974 | MockRead data_reads2[] = { |
| 3975 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3976 | |
| 3977 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3978 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3979 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3980 | MockRead(SYNCHRONOUS, "hello"), |
| 3981 | }; |
| 3982 | |
| 3983 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3984 | data_writes1, arraysize(data_writes1)); |
| 3985 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3986 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3987 | data_writes2, arraysize(data_writes2)); |
| 3988 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3989 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3992 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3994 | |
| 3995 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3996 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3997 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3998 | |
| 3999 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4000 | ASSERT_TRUE(response); |
| 4001 | ASSERT_TRUE(response->headers); |
| 4002 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4003 | EXPECT_EQ(407, response->headers->response_code()); |
| 4004 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4005 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4006 | EXPECT_FALSE(response->auth_challenge); |
| 4007 | |
| 4008 | LoadTimingInfo load_timing_info; |
| 4009 | // CONNECT requests and responses are handled at the connect job level, so |
| 4010 | // the transaction does not yet have a connection. |
| 4011 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4012 | |
| 4013 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4014 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4015 | |
| 4016 | response = trans->GetResponseInfo(); |
| 4017 | ASSERT_TRUE(response); |
| 4018 | ASSERT_TRUE(response->headers); |
| 4019 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4020 | EXPECT_EQ(200, response->headers->response_code()); |
| 4021 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4022 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4023 | |
| 4024 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4025 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4026 | |
| 4027 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4028 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4029 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4030 | |
| 4031 | trans.reset(); |
| 4032 | session->CloseAllConnections(); |
| 4033 | } |
| 4034 | |
| 4035 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4036 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4037 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4038 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4039 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4040 | HttpRequestInfo request; |
| 4041 | request.method = "GET"; |
| 4042 | request.url = GURL("https://www.example.org/"); |
| 4043 | |
| 4044 | // Configure against proxy server "myproxy:70". |
| 4045 | session_deps_.proxy_service = |
| 4046 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4047 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4048 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4049 | new HttpAuthHandlerMock::Factory()); |
| 4050 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4051 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4052 | mock_handler->set_allows_default_credentials(true); |
| 4053 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4054 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4055 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4056 | |
| 4057 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4058 | NetLog net_log; |
| 4059 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4060 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4061 | |
| 4062 | // Should try to establish tunnel. |
| 4063 | MockWrite data_writes1[] = { |
| 4064 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4065 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4066 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4067 | |
| 4068 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4069 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4070 | "Proxy-Connection: keep-alive\r\n" |
| 4071 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4072 | }; |
| 4073 | |
| 4074 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4075 | // second request is sent. |
| 4076 | MockRead data_reads1[] = { |
| 4077 | // No credentials. |
| 4078 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4079 | MockRead("Content-Length: 0\r\n"), |
| 4080 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4081 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4082 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4083 | }; |
| 4084 | |
| 4085 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4086 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4087 | // request. |
| 4088 | MockWrite data_writes2[] = { |
| 4089 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4090 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4091 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4092 | }; |
| 4093 | |
| 4094 | // The proxy, having had more than enough of us, just hangs up. |
| 4095 | MockRead data_reads2[] = { |
| 4096 | // No credentials. |
| 4097 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4098 | }; |
| 4099 | |
| 4100 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4101 | data_writes1, arraysize(data_writes1)); |
| 4102 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4103 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4104 | data_writes2, arraysize(data_writes2)); |
| 4105 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4107 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4108 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4109 | |
| 4110 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4111 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4112 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4113 | |
| 4114 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4115 | ASSERT_TRUE(response); |
| 4116 | ASSERT_TRUE(response->headers); |
| 4117 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4118 | EXPECT_EQ(407, response->headers->response_code()); |
| 4119 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4120 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4121 | EXPECT_FALSE(response->auth_challenge); |
| 4122 | |
| 4123 | LoadTimingInfo load_timing_info; |
| 4124 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4125 | |
| 4126 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4127 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4128 | |
| 4129 | trans.reset(); |
| 4130 | session->CloseAllConnections(); |
| 4131 | } |
| 4132 | |
| 4133 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4134 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4135 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4136 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4137 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4138 | HttpRequestInfo request; |
| 4139 | request.method = "GET"; |
| 4140 | request.url = GURL("https://www.example.org/"); |
| 4141 | |
| 4142 | // Configure against proxy server "myproxy:70". |
| 4143 | session_deps_.proxy_service = |
| 4144 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4146 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4147 | new HttpAuthHandlerMock::Factory()); |
| 4148 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4149 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4150 | mock_handler->set_allows_default_credentials(true); |
| 4151 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4152 | HttpAuth::AUTH_PROXY); |
| 4153 | // Add another handler for the second challenge. It supports default |
| 4154 | // credentials, but they shouldn't be used, since they were already tried. |
| 4155 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4156 | mock_handler->set_allows_default_credentials(true); |
| 4157 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4158 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4159 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | |
| 4161 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4162 | NetLog net_log; |
| 4163 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4164 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | |
| 4166 | // Should try to establish tunnel. |
| 4167 | MockWrite data_writes1[] = { |
| 4168 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4169 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4170 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4171 | }; |
| 4172 | |
| 4173 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4174 | // connection. |
| 4175 | MockRead data_reads1[] = { |
| 4176 | // No credentials. |
| 4177 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4178 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4179 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4180 | }; |
| 4181 | |
| 4182 | // Since the first connection was closed, need to establish another once given |
| 4183 | // credentials. |
| 4184 | MockWrite data_writes2[] = { |
| 4185 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4186 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | "Proxy-Connection: keep-alive\r\n" |
| 4188 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4189 | }; |
| 4190 | |
| 4191 | MockRead data_reads2[] = { |
| 4192 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4193 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4194 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4195 | }; |
| 4196 | |
| 4197 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4198 | data_writes1, arraysize(data_writes1)); |
| 4199 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4200 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4201 | data_writes2, arraysize(data_writes2)); |
| 4202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4203 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4206 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4208 | |
| 4209 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4210 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4211 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | |
| 4213 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4214 | ASSERT_TRUE(response); |
| 4215 | ASSERT_TRUE(response->headers); |
| 4216 | EXPECT_EQ(407, response->headers->response_code()); |
| 4217 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4218 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4219 | EXPECT_FALSE(response->auth_challenge); |
| 4220 | |
| 4221 | LoadTimingInfo load_timing_info; |
| 4222 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4223 | |
| 4224 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4225 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4226 | response = trans->GetResponseInfo(); |
| 4227 | ASSERT_TRUE(response); |
| 4228 | ASSERT_TRUE(response->headers); |
| 4229 | EXPECT_EQ(407, response->headers->response_code()); |
| 4230 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4231 | EXPECT_TRUE(response->auth_challenge); |
| 4232 | |
| 4233 | trans.reset(); |
| 4234 | session->CloseAllConnections(); |
| 4235 | } |
| 4236 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4237 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4238 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4239 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4240 | // authentication handshake can continue with the same scheme but with a |
| 4241 | // different identity. |
| 4242 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4243 | HttpRequestInfo request; |
| 4244 | request.method = "GET"; |
| 4245 | request.url = GURL("http://www.example.org/"); |
| 4246 | |
| 4247 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 4248 | new HttpAuthHandlerMock::Factory()); |
| 4249 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4250 | |
| 4251 | // First handler. Uses default credentials, but barfs at generate auth token. |
| 4252 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 4253 | mock_handler->set_allows_default_credentials(true); |
| 4254 | mock_handler->set_allows_explicit_credentials(true); |
| 4255 | mock_handler->set_connection_based(true); |
| 4256 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4257 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4258 | HttpAuth::AUTH_SERVER); |
| 4259 | |
| 4260 | // Add another handler for the second challenge. It supports default |
| 4261 | // credentials, but they shouldn't be used, since they were already tried. |
| 4262 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4263 | mock_handler->set_allows_default_credentials(true); |
| 4264 | mock_handler->set_allows_explicit_credentials(true); |
| 4265 | mock_handler->set_connection_based(true); |
| 4266 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4267 | HttpAuth::AUTH_SERVER); |
| 4268 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4269 | |
| 4270 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4271 | |
| 4272 | MockWrite data_writes1[] = { |
| 4273 | MockWrite("GET / HTTP/1.1\r\n" |
| 4274 | "Host: www.example.org\r\n" |
| 4275 | "Connection: keep-alive\r\n\r\n"), |
| 4276 | }; |
| 4277 | |
| 4278 | MockRead data_reads1[] = { |
| 4279 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4280 | "WWW-Authenticate: Mock\r\n" |
| 4281 | "Connection: keep-alive\r\n\r\n"), |
| 4282 | }; |
| 4283 | |
| 4284 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4285 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4286 | // transaction procceds without an authorization header. |
| 4287 | MockWrite data_writes2[] = { |
| 4288 | MockWrite("GET / HTTP/1.1\r\n" |
| 4289 | "Host: www.example.org\r\n" |
| 4290 | "Connection: keep-alive\r\n\r\n"), |
| 4291 | }; |
| 4292 | |
| 4293 | MockRead data_reads2[] = { |
| 4294 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4295 | "WWW-Authenticate: Mock\r\n" |
| 4296 | "Connection: keep-alive\r\n\r\n"), |
| 4297 | }; |
| 4298 | |
| 4299 | MockWrite data_writes3[] = { |
| 4300 | MockWrite("GET / HTTP/1.1\r\n" |
| 4301 | "Host: www.example.org\r\n" |
| 4302 | "Connection: keep-alive\r\n" |
| 4303 | "Authorization: auth_token\r\n\r\n"), |
| 4304 | }; |
| 4305 | |
| 4306 | MockRead data_reads3[] = { |
| 4307 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4308 | "Content-Length: 5\r\n" |
| 4309 | "Content-Type: text/plain\r\n" |
| 4310 | "Connection: keep-alive\r\n\r\n" |
| 4311 | "Hello"), |
| 4312 | }; |
| 4313 | |
| 4314 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4315 | data_writes1, arraysize(data_writes1)); |
| 4316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4317 | |
| 4318 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4319 | data_writes2, arraysize(data_writes2)); |
| 4320 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4321 | |
| 4322 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4323 | data_writes3, arraysize(data_writes3)); |
| 4324 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4325 | |
| 4326 | std::unique_ptr<HttpNetworkTransaction> trans( |
| 4327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4328 | |
| 4329 | TestCompletionCallback callback; |
| 4330 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4331 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4332 | |
| 4333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4334 | ASSERT_TRUE(response); |
| 4335 | ASSERT_TRUE(response->headers); |
| 4336 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4337 | |
| 4338 | // The following three tests assert that an authentication challenge was |
| 4339 | // received and that the stack is ready to respond to the challenge using |
| 4340 | // ambient credentials. |
| 4341 | EXPECT_EQ(401, response->headers->response_code()); |
| 4342 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4343 | EXPECT_FALSE(response->auth_challenge); |
| 4344 | |
| 4345 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4346 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4347 | response = trans->GetResponseInfo(); |
| 4348 | ASSERT_TRUE(response); |
| 4349 | ASSERT_TRUE(response->headers); |
| 4350 | |
| 4351 | // The following three tests assert that an authentication challenge was |
| 4352 | // received and that the stack needs explicit credentials before it is ready |
| 4353 | // to respond to the challenge. |
| 4354 | EXPECT_EQ(401, response->headers->response_code()); |
| 4355 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4356 | EXPECT_TRUE(response->auth_challenge); |
| 4357 | |
| 4358 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4359 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4360 | response = trans->GetResponseInfo(); |
| 4361 | ASSERT_TRUE(response); |
| 4362 | ASSERT_TRUE(response->headers); |
| 4363 | EXPECT_EQ(200, response->headers->response_code()); |
| 4364 | |
| 4365 | trans.reset(); |
| 4366 | session->CloseAllConnections(); |
| 4367 | } |
| 4368 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4369 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4370 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4371 | HttpRequestInfo request1; |
| 4372 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4373 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4374 | |
| 4375 | HttpRequestInfo request2; |
| 4376 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4377 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4378 | |
| 4379 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4380 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4381 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4382 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4384 | |
| 4385 | // Since we have proxy, should try to establish tunnel. |
| 4386 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4387 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4388 | "Host: www.example.org:443\r\n" |
| 4389 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4390 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4391 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4392 | "Host: www.example.org\r\n" |
| 4393 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4394 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4395 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4396 | "Host: www.example.org\r\n" |
| 4397 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4398 | }; |
| 4399 | |
| 4400 | // The proxy responds to the connect with a 407, using a persistent |
| 4401 | // connection. |
| 4402 | MockRead data_reads1[] = { |
| 4403 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4404 | |
| 4405 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4406 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4407 | MockRead(SYNCHRONOUS, "1"), |
| 4408 | |
| 4409 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4410 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4411 | MockRead(SYNCHRONOUS, "22"), |
| 4412 | }; |
| 4413 | |
| 4414 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4415 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4416 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4417 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4419 | |
| 4420 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4421 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4422 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4423 | |
| 4424 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4426 | |
| 4427 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4429 | |
| 4430 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4431 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4432 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4433 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4434 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4435 | |
| 4436 | LoadTimingInfo load_timing_info1; |
| 4437 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4438 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4439 | |
| 4440 | trans1.reset(); |
| 4441 | |
| 4442 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4443 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4445 | |
| 4446 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4448 | |
| 4449 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4450 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4451 | |
| 4452 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4453 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4454 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4455 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4456 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4457 | |
| 4458 | LoadTimingInfo load_timing_info2; |
| 4459 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4460 | TestLoadTimingReused(load_timing_info2); |
| 4461 | |
| 4462 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4463 | |
| 4464 | trans2.reset(); |
| 4465 | session->CloseAllConnections(); |
| 4466 | } |
| 4467 | |
| 4468 | // 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] | 4469 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4470 | HttpRequestInfo request1; |
| 4471 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4472 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4473 | |
| 4474 | HttpRequestInfo request2; |
| 4475 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4476 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4477 | |
| 4478 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4479 | session_deps_.proxy_service = |
| 4480 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4481 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4482 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4484 | |
| 4485 | // Since we have proxy, should try to establish tunnel. |
| 4486 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4487 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4488 | "Host: www.example.org:443\r\n" |
| 4489 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4490 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4491 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4492 | "Host: www.example.org\r\n" |
| 4493 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4494 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4495 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4496 | "Host: www.example.org\r\n" |
| 4497 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4498 | }; |
| 4499 | |
| 4500 | // The proxy responds to the connect with a 407, using a persistent |
| 4501 | // connection. |
| 4502 | MockRead data_reads1[] = { |
| 4503 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4504 | |
| 4505 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4506 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4507 | MockRead(SYNCHRONOUS, "1"), |
| 4508 | |
| 4509 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4510 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4511 | MockRead(SYNCHRONOUS, "22"), |
| 4512 | }; |
| 4513 | |
| 4514 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4515 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4516 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4517 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4519 | |
| 4520 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4521 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4522 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4523 | |
| 4524 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4525 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4526 | |
| 4527 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4528 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4529 | |
| 4530 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4531 | ASSERT_TRUE(response1); |
| 4532 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4533 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4534 | |
| 4535 | LoadTimingInfo load_timing_info1; |
| 4536 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4537 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4538 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4539 | |
| 4540 | trans1.reset(); |
| 4541 | |
| 4542 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4543 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4544 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4545 | |
| 4546 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4548 | |
| 4549 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4551 | |
| 4552 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4553 | ASSERT_TRUE(response2); |
| 4554 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4555 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4556 | |
| 4557 | LoadTimingInfo load_timing_info2; |
| 4558 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4559 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4560 | |
| 4561 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4562 | |
| 4563 | trans2.reset(); |
| 4564 | session->CloseAllConnections(); |
| 4565 | } |
| 4566 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4567 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4568 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4569 | HttpRequestInfo request; |
| 4570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4571 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4572 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4573 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4574 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4575 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4576 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4578 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4579 | // Since we have proxy, should use full url |
| 4580 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4581 | MockWrite( |
| 4582 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4583 | "Host: www.example.org\r\n" |
| 4584 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4585 | }; |
| 4586 | |
| 4587 | MockRead data_reads1[] = { |
| 4588 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4589 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4590 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4591 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4592 | }; |
| 4593 | |
| 4594 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4595 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4596 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4597 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4598 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4600 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4604 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4606 | |
| 4607 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4608 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4609 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4610 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4611 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4612 | TestLoadTimingNotReused(load_timing_info, |
| 4613 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4615 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4616 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4617 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4618 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4619 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4620 | EXPECT_EQ(200, response->headers->response_code()); |
| 4621 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4622 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4623 | |
| 4624 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4625 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4626 | } |
| 4627 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4628 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4629 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4630 | HttpRequestInfo request; |
| 4631 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4632 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4633 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4634 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4635 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4636 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4637 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4639 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4640 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4641 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4642 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4643 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4644 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4645 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4646 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4647 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4648 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4649 | }; |
| 4650 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4651 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4652 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4653 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4654 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4655 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4656 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4659 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4661 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4663 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4665 | |
| 4666 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4667 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4668 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4669 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4670 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4671 | TestLoadTimingNotReused(load_timing_info, |
| 4672 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4674 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4675 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4676 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4677 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4678 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4679 | |
| 4680 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4681 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4682 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4683 | } |
| 4684 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4685 | // Verifies that a session which races and wins against the owning transaction |
| 4686 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4687 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4688 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4689 | HttpRequestInfo request; |
| 4690 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4691 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4692 | |
| 4693 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4694 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4695 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4696 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4698 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4699 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4700 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4701 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4702 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4703 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4704 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4705 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4706 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4707 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4708 | }; |
| 4709 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4710 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4711 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4712 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4713 | |
| 4714 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4715 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4717 | |
| 4718 | TestCompletionCallback callback1; |
| 4719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4721 | |
| 4722 | // Stall the hostname resolution begun by the transaction. |
| 4723 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4724 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4726 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4728 | |
| 4729 | // Race a session to the proxy, which completes first. |
| 4730 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4731 | SpdySessionKey key( |
| 4732 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4733 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4734 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4735 | |
| 4736 | // Unstall the resolution begun by the transaction. |
| 4737 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4738 | session_deps_.host_resolver->ResolveAllPending(); |
| 4739 | |
| 4740 | EXPECT_FALSE(callback1.have_result()); |
| 4741 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4742 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4745 | ASSERT_TRUE(response); |
| 4746 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4747 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4748 | |
| 4749 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4750 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4751 | EXPECT_EQ(kUploadData, response_data); |
| 4752 | } |
| 4753 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4754 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4755 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4756 | HttpRequestInfo request; |
| 4757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4758 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4759 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4760 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4761 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4762 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4763 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4765 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4766 | // The first request will be a bare GET, the second request will be a |
| 4767 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4768 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4769 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4770 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4771 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4772 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4773 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4774 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4775 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4776 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4777 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4778 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4779 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4780 | }; |
| 4781 | |
| 4782 | // The first response is a 407 proxy authentication challenge, and the second |
| 4783 | // response will be a 200 response since the second request includes a valid |
| 4784 | // Authorization header. |
| 4785 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4786 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4787 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4788 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4789 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4790 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4791 | SpdySerializedFrame body_authentication( |
| 4792 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4793 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4794 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4795 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4796 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4797 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4798 | CreateMockRead(resp_data, 4), |
| 4799 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4800 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4801 | }; |
| 4802 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4803 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4804 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4806 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4807 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4808 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4811 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4815 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4817 | |
| 4818 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4819 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4821 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4822 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4823 | ASSERT_TRUE(response); |
| 4824 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4825 | EXPECT_EQ(407, response->headers->response_code()); |
| 4826 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4827 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4829 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4831 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4833 | |
| 4834 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4835 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4837 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4838 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4839 | ASSERT_TRUE(response_restart); |
| 4840 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4841 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4842 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4843 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4844 | } |
| 4845 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4846 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4847 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4848 | HttpRequestInfo request; |
| 4849 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4850 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4851 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4852 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4853 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4854 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4855 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4859 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4860 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4861 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4862 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4863 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4864 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4865 | const char get[] = |
| 4866 | "GET / HTTP/1.1\r\n" |
| 4867 | "Host: www.example.org\r\n" |
| 4868 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4869 | SpdySerializedFrame wrapped_get( |
| 4870 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4871 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4872 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4873 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4874 | SpdySerializedFrame wrapped_get_resp( |
| 4875 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4876 | SpdySerializedFrame wrapped_body( |
| 4877 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4878 | SpdySerializedFrame window_update( |
| 4879 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4880 | |
| 4881 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4882 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4883 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4884 | }; |
| 4885 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4886 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4887 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4888 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4889 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4890 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4891 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4892 | }; |
| 4893 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4894 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4895 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4896 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4897 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4898 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4899 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4901 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4904 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4906 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4908 | |
| 4909 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4910 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4911 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4912 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4913 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4914 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4916 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4917 | ASSERT_TRUE(response); |
| 4918 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4919 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4920 | |
| 4921 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4922 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4923 | EXPECT_EQ("1234567890", response_data); |
| 4924 | } |
| 4925 | |
| 4926 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4927 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4928 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4929 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4930 | HttpRequestInfo request; |
| 4931 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4932 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4933 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4934 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4935 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4936 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4937 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4941 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4942 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4943 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4944 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4945 | // fetch https://www.example.org/ via SPDY |
| 4946 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4947 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4948 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4950 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4951 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4952 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4953 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4954 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4955 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4956 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4957 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4958 | SpdySerializedFrame window_update_get_resp( |
| 4959 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4960 | SpdySerializedFrame window_update_body( |
| 4961 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4962 | |
| 4963 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4964 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4965 | CreateMockWrite(window_update_get_resp, 6), |
| 4966 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4967 | }; |
| 4968 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4969 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4970 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4971 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4972 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4973 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4974 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4975 | }; |
| 4976 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4977 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4978 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4979 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4980 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4981 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4982 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4984 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4985 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4988 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4990 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4992 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4993 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4994 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4995 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4996 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4997 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4998 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4999 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5000 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5001 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5002 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5004 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5005 | ASSERT_TRUE(response); |
| 5006 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5007 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5008 | |
| 5009 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5010 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5011 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5015 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5016 | HttpRequestInfo request; |
| 5017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5018 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5019 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5020 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5021 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5022 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5023 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5026 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5027 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5028 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5029 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5030 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5031 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame^] | 5032 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5033 | |
| 5034 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5035 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5036 | }; |
| 5037 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5038 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5039 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5040 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5041 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5042 | }; |
| 5043 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5044 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5045 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5046 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5047 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5048 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5049 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5051 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5052 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5055 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5057 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5059 | |
| 5060 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5061 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5062 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5063 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5064 | } |
| 5065 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5066 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5067 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5068 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5069 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5070 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5071 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5072 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5073 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5074 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5075 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5076 | |
| 5077 | HttpRequestInfo request1; |
| 5078 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5079 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5080 | request1.load_flags = 0; |
| 5081 | |
| 5082 | HttpRequestInfo request2; |
| 5083 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5084 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5085 | request2.load_flags = 0; |
| 5086 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5087 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5088 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5089 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5090 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5091 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5092 | // Fetch https://www.example.org/ via HTTP. |
| 5093 | const char get1[] = |
| 5094 | "GET / HTTP/1.1\r\n" |
| 5095 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5096 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5097 | SpdySerializedFrame wrapped_get1( |
| 5098 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5099 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5100 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5101 | SpdySerializedFrame wrapped_get_resp1( |
| 5102 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5103 | SpdySerializedFrame wrapped_body1( |
| 5104 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5105 | SpdySerializedFrame window_update( |
| 5106 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5107 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5108 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5109 | SpdyHeaderBlock connect2_block; |
| 5110 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5111 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5112 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5113 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5114 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5115 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5116 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5117 | // Fetch https://mail.example.org/ via HTTP. |
| 5118 | const char get2[] = |
| 5119 | "GET / HTTP/1.1\r\n" |
| 5120 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5121 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5122 | SpdySerializedFrame wrapped_get2( |
| 5123 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5124 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5125 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5126 | SpdySerializedFrame wrapped_get_resp2( |
| 5127 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5128 | SpdySerializedFrame wrapped_body2( |
| 5129 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5130 | |
| 5131 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5132 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5133 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5134 | }; |
| 5135 | |
| 5136 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5137 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5138 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5139 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5140 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5141 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5142 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5143 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5144 | }; |
| 5145 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5146 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5147 | arraysize(spdy_writes)); |
| 5148 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5149 | |
| 5150 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5151 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5153 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5155 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5156 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5157 | |
| 5158 | TestCompletionCallback callback; |
| 5159 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5160 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5161 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5162 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5163 | |
| 5164 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5165 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5166 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5168 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5169 | ASSERT_TRUE(response); |
| 5170 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5171 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5172 | |
| 5173 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5174 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5175 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5176 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5178 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5179 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5180 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5181 | |
| 5182 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5183 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5184 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5185 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5186 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5187 | |
| 5188 | // The requests should have different IDs, since they each are using their own |
| 5189 | // separate stream. |
| 5190 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5192 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5193 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5197 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5198 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5199 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5200 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5201 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5202 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5203 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5204 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5205 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5206 | |
| 5207 | HttpRequestInfo request1; |
| 5208 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5209 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5210 | request1.load_flags = 0; |
| 5211 | |
| 5212 | HttpRequestInfo request2; |
| 5213 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5214 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5215 | request2.load_flags = 0; |
| 5216 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5217 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5218 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5219 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5220 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5221 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5222 | // Fetch https://www.example.org/ via HTTP. |
| 5223 | const char get1[] = |
| 5224 | "GET / HTTP/1.1\r\n" |
| 5225 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5226 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5227 | SpdySerializedFrame wrapped_get1( |
| 5228 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5229 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5230 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5231 | SpdySerializedFrame wrapped_get_resp1( |
| 5232 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5233 | SpdySerializedFrame wrapped_body1( |
| 5234 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5235 | SpdySerializedFrame window_update( |
| 5236 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5237 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5238 | // Fetch https://www.example.org/2 via HTTP. |
| 5239 | const char get2[] = |
| 5240 | "GET /2 HTTP/1.1\r\n" |
| 5241 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5242 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5243 | SpdySerializedFrame wrapped_get2( |
| 5244 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5245 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5246 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5247 | SpdySerializedFrame wrapped_get_resp2( |
| 5248 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5249 | SpdySerializedFrame wrapped_body2( |
| 5250 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5251 | |
| 5252 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5253 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5254 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5255 | }; |
| 5256 | |
| 5257 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5258 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5259 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5260 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5261 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5262 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5263 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5264 | }; |
| 5265 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5266 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5267 | arraysize(spdy_writes)); |
| 5268 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5269 | |
| 5270 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5271 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5273 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5275 | |
| 5276 | TestCompletionCallback callback; |
| 5277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5278 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5280 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5282 | |
| 5283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5285 | |
| 5286 | LoadTimingInfo load_timing_info; |
| 5287 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5288 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5289 | |
| 5290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5291 | ASSERT_TRUE(response); |
| 5292 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5294 | |
| 5295 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5296 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5297 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5298 | trans.reset(); |
| 5299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5300 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5301 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5302 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5303 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5304 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5305 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5306 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5307 | |
| 5308 | LoadTimingInfo load_timing_info2; |
| 5309 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5310 | TestLoadTimingReused(load_timing_info2); |
| 5311 | |
| 5312 | // The requests should have the same ID. |
| 5313 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5314 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5315 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5319 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5320 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5321 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5322 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5323 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5324 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5325 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5326 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5327 | |
| 5328 | HttpRequestInfo request1; |
| 5329 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5330 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5331 | request1.load_flags = 0; |
| 5332 | |
| 5333 | HttpRequestInfo request2; |
| 5334 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5335 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5336 | request2.load_flags = 0; |
| 5337 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5338 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5339 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5340 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5342 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5343 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5344 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5345 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5346 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5347 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5348 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5349 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5350 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5351 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5352 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5353 | SpdySerializedFrame body2( |
| 5354 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5355 | |
| 5356 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5357 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5358 | }; |
| 5359 | |
| 5360 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5361 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5362 | CreateMockRead(body1, 2, ASYNC), |
| 5363 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5364 | CreateMockRead(body2, 5, ASYNC), |
| 5365 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5366 | }; |
| 5367 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5368 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5369 | arraysize(spdy_writes)); |
| 5370 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5371 | |
| 5372 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5373 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5375 | |
| 5376 | TestCompletionCallback callback; |
| 5377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5378 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5379 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5380 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5381 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5382 | |
| 5383 | LoadTimingInfo load_timing_info; |
| 5384 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5385 | TestLoadTimingNotReused(load_timing_info, |
| 5386 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5387 | |
| 5388 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5389 | ASSERT_TRUE(response); |
| 5390 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5391 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5392 | |
| 5393 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5394 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5395 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5396 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5397 | // Delete the first request, so the second one can reuse the socket. |
| 5398 | trans.reset(); |
| 5399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5400 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5401 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5402 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5403 | |
| 5404 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5405 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5406 | TestLoadTimingReused(load_timing_info2); |
| 5407 | |
| 5408 | // The requests should have the same ID. |
| 5409 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5411 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5412 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5413 | } |
| 5414 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5415 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5416 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | HttpRequestInfo request; |
| 5418 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5419 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5421 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5422 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5423 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5424 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5425 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5426 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5428 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5429 | // Since we have proxy, should use full url |
| 5430 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5431 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5432 | "Host: www.example.org\r\n" |
| 5433 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5435 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5436 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5437 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5438 | "Host: www.example.org\r\n" |
| 5439 | "Proxy-Connection: keep-alive\r\n" |
| 5440 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5441 | }; |
| 5442 | |
| 5443 | // The proxy responds to the GET with a 407, using a persistent |
| 5444 | // connection. |
| 5445 | MockRead data_reads1[] = { |
| 5446 | // No credentials. |
| 5447 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5448 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5449 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5450 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5451 | |
| 5452 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5454 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5455 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5456 | }; |
| 5457 | |
| 5458 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5459 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5460 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5461 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5464 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5468 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5470 | |
| 5471 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5473 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5474 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5475 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5476 | TestLoadTimingNotReused(load_timing_info, |
| 5477 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5479 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5480 | ASSERT_TRUE(response); |
| 5481 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5482 | EXPECT_EQ(407, response->headers->response_code()); |
| 5483 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5484 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5486 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5488 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5490 | |
| 5491 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5493 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5494 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5495 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5496 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5497 | TestLoadTimingReused(load_timing_info); |
| 5498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5499 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5500 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5501 | |
| 5502 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5503 | EXPECT_EQ(200, response->headers->response_code()); |
| 5504 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5505 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5506 | |
| 5507 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5508 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5509 | } |
| 5510 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5511 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5512 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5513 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5514 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5515 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5516 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5517 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5518 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5520 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5521 | // Since we have proxy, should try to establish tunnel. |
| 5522 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5523 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5524 | "Host: www.example.org:443\r\n" |
| 5525 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5526 | }; |
| 5527 | |
| 5528 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5529 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5530 | // No response body because the test stops reading here. |
| 5531 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5532 | }; |
| 5533 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5534 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5535 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5536 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5537 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5538 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5540 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5541 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5542 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5544 | |
| 5545 | rv = callback.WaitForResult(); |
| 5546 | EXPECT_EQ(expected_status, rv); |
| 5547 | } |
| 5548 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5549 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5550 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5551 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5552 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5553 | } |
| 5554 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5555 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5556 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5557 | } |
| 5558 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5559 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5560 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5561 | } |
| 5562 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5563 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5564 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5565 | } |
| 5566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5567 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5568 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5569 | } |
| 5570 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5571 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5572 | ConnectStatusHelper( |
| 5573 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5574 | } |
| 5575 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5576 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5577 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5578 | } |
| 5579 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5580 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5581 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5582 | } |
| 5583 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5584 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5585 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5586 | } |
| 5587 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5588 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5589 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5590 | } |
| 5591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5592 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5593 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5594 | } |
| 5595 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5596 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5597 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5598 | } |
| 5599 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5600 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5601 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5602 | } |
| 5603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5604 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5605 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5606 | } |
| 5607 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5608 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5609 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5610 | } |
| 5611 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5612 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5613 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5614 | } |
| 5615 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5616 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5617 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5618 | } |
| 5619 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5620 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5621 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5622 | } |
| 5623 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5624 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5625 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5626 | } |
| 5627 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5628 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5629 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5630 | } |
| 5631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5632 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5633 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5634 | } |
| 5635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5636 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5637 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5638 | } |
| 5639 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5640 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5641 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5642 | } |
| 5643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5644 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5645 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5646 | } |
| 5647 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5648 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5649 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5650 | } |
| 5651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5652 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5653 | ConnectStatusHelperWithExpectedStatus( |
| 5654 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5655 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5656 | } |
| 5657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5658 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5659 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5660 | } |
| 5661 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5662 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5663 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5664 | } |
| 5665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5666 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5667 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5668 | } |
| 5669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5670 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5671 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5672 | } |
| 5673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5674 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5675 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5676 | } |
| 5677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5678 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5679 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5680 | } |
| 5681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5682 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5683 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5684 | } |
| 5685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5686 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5687 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5688 | } |
| 5689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5690 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5691 | ConnectStatusHelper( |
| 5692 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5693 | } |
| 5694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5695 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5696 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5697 | } |
| 5698 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5699 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5700 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5701 | } |
| 5702 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5703 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5704 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5705 | } |
| 5706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5707 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5708 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5709 | } |
| 5710 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5711 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5712 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5713 | } |
| 5714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5715 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5716 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5717 | } |
| 5718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5719 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5720 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5721 | } |
| 5722 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5723 | // Test the flow when both the proxy server AND origin server require |
| 5724 | // authentication. Again, this uses basic auth for both since that is |
| 5725 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5726 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5727 | HttpRequestInfo request; |
| 5728 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5729 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5730 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5731 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5732 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5733 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5736 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5737 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5738 | MockWrite( |
| 5739 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5740 | "Host: www.example.org\r\n" |
| 5741 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5742 | }; |
| 5743 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5744 | MockRead data_reads1[] = { |
| 5745 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5746 | // Give a couple authenticate options (only the middle one is actually |
| 5747 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5748 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5749 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5750 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5752 | // Large content-length -- won't matter, as connection will be reset. |
| 5753 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5754 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5755 | }; |
| 5756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5757 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5758 | // request we should be issuing -- the final header line contains the |
| 5759 | // proxy's credentials. |
| 5760 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5761 | MockWrite( |
| 5762 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5763 | "Host: www.example.org\r\n" |
| 5764 | "Proxy-Connection: keep-alive\r\n" |
| 5765 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5766 | }; |
| 5767 | |
| 5768 | // Now the proxy server lets the request pass through to origin server. |
| 5769 | // The origin server responds with a 401. |
| 5770 | MockRead data_reads2[] = { |
| 5771 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5772 | // Note: We are using the same realm-name as the proxy server. This is |
| 5773 | // completely valid, as realms are unique across hosts. |
| 5774 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5775 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5776 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5777 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5778 | }; |
| 5779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5780 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5781 | // the credentials for both the proxy and origin server. |
| 5782 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5783 | MockWrite( |
| 5784 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5785 | "Host: www.example.org\r\n" |
| 5786 | "Proxy-Connection: keep-alive\r\n" |
| 5787 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5788 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5789 | }; |
| 5790 | |
| 5791 | // Lastly we get the desired content. |
| 5792 | MockRead data_reads3[] = { |
| 5793 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5794 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5795 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5796 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5797 | }; |
| 5798 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5799 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5800 | data_writes1, arraysize(data_writes1)); |
| 5801 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5802 | data_writes2, arraysize(data_writes2)); |
| 5803 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5804 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5805 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5806 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5807 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5809 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5811 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5813 | |
| 5814 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5815 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5818 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5819 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5821 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5823 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5825 | |
| 5826 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5830 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5831 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5833 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5835 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5836 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5838 | |
| 5839 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5841 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5842 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5843 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5844 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5845 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5846 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5847 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5848 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5849 | // authorization headers. |
| 5850 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5851 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5852 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5853 | // bytes in the debugger. |
| 5854 | |
| 5855 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5856 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5857 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5858 | request.method = "GET"; |
| 5859 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5860 | |
| 5861 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5862 | // to other auth schemes. |
| 5863 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5864 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5865 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5866 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5868 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5869 | MockWrite data_writes1[] = { |
| 5870 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5871 | "Host: 172.22.68.17\r\n" |
| 5872 | "Connection: keep-alive\r\n\r\n"), |
| 5873 | }; |
| 5874 | |
| 5875 | MockRead data_reads1[] = { |
| 5876 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5877 | // Negotiate and NTLM are often requested together. However, we only want |
| 5878 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5879 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5880 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5881 | MockRead("Connection: close\r\n"), |
| 5882 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5883 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5884 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5885 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5886 | }; |
| 5887 | |
| 5888 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5889 | // After restarting with a null identity, this is the |
| 5890 | // request we should be issuing -- the final header line contains a Type |
| 5891 | // 1 message. |
| 5892 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5893 | "Host: 172.22.68.17\r\n" |
| 5894 | "Connection: keep-alive\r\n" |
| 5895 | "Authorization: NTLM " |
| 5896 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5898 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5899 | // (the credentials for the origin server). The second request continues |
| 5900 | // on the same connection. |
| 5901 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5902 | "Host: 172.22.68.17\r\n" |
| 5903 | "Connection: keep-alive\r\n" |
| 5904 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5905 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5906 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5907 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5908 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5909 | }; |
| 5910 | |
| 5911 | MockRead data_reads2[] = { |
| 5912 | // The origin server responds with a Type 2 message. |
| 5913 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5914 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5915 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5916 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5917 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5918 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5919 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5920 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5921 | "BtAAAAAAA=\r\n"), |
| 5922 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5923 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5924 | MockRead("You are not authorized to view this page\r\n"), |
| 5925 | |
| 5926 | // Lastly we get the desired content. |
| 5927 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5928 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5929 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5930 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5932 | }; |
| 5933 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5934 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5935 | data_writes1, arraysize(data_writes1)); |
| 5936 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5937 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5938 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5939 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5941 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5945 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5947 | |
| 5948 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5951 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5954 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5955 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5957 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5959 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5960 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5962 | |
| 5963 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5966 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5968 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5969 | ASSERT_TRUE(response); |
| 5970 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5972 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5974 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5975 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5976 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5977 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5978 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5980 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5981 | ASSERT_TRUE(response); |
| 5982 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5983 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5984 | } |
| 5985 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5986 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5987 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5988 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5989 | request.method = "GET"; |
| 5990 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5991 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5992 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5993 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5995 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5996 | MockWrite data_writes1[] = { |
| 5997 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5998 | "Host: 172.22.68.17\r\n" |
| 5999 | "Connection: keep-alive\r\n\r\n"), |
| 6000 | }; |
| 6001 | |
| 6002 | MockRead data_reads1[] = { |
| 6003 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6004 | // Negotiate and NTLM are often requested together. However, we only want |
| 6005 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6006 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6007 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6008 | MockRead("Connection: close\r\n"), |
| 6009 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6010 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6011 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6012 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6013 | }; |
| 6014 | |
| 6015 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6016 | // After restarting with a null identity, this is the |
| 6017 | // request we should be issuing -- the final header line contains a Type |
| 6018 | // 1 message. |
| 6019 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6020 | "Host: 172.22.68.17\r\n" |
| 6021 | "Connection: keep-alive\r\n" |
| 6022 | "Authorization: NTLM " |
| 6023 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6025 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6026 | // (the credentials for the origin server). The second request continues |
| 6027 | // on the same connection. |
| 6028 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6029 | "Host: 172.22.68.17\r\n" |
| 6030 | "Connection: keep-alive\r\n" |
| 6031 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6032 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6033 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6034 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6035 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6036 | }; |
| 6037 | |
| 6038 | MockRead data_reads2[] = { |
| 6039 | // The origin server responds with a Type 2 message. |
| 6040 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6041 | MockRead("WWW-Authenticate: NTLM " |
| 6042 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6043 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6044 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6045 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6046 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6047 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6048 | "BtAAAAAAA=\r\n"), |
| 6049 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6050 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6051 | MockRead("You are not authorized to view this page\r\n"), |
| 6052 | |
| 6053 | // Wrong password. |
| 6054 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6055 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6056 | MockRead("Connection: close\r\n"), |
| 6057 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6058 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6059 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6060 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6061 | }; |
| 6062 | |
| 6063 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6064 | // After restarting with a null identity, this is the |
| 6065 | // request we should be issuing -- the final header line contains a Type |
| 6066 | // 1 message. |
| 6067 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6068 | "Host: 172.22.68.17\r\n" |
| 6069 | "Connection: keep-alive\r\n" |
| 6070 | "Authorization: NTLM " |
| 6071 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6073 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6074 | // (the credentials for the origin server). The second request continues |
| 6075 | // on the same connection. |
| 6076 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6077 | "Host: 172.22.68.17\r\n" |
| 6078 | "Connection: keep-alive\r\n" |
| 6079 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6080 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6081 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6082 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6083 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6084 | }; |
| 6085 | |
| 6086 | MockRead data_reads3[] = { |
| 6087 | // The origin server responds with a Type 2 message. |
| 6088 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6089 | MockRead("WWW-Authenticate: NTLM " |
| 6090 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6091 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6092 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6093 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6094 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6095 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6096 | "BtAAAAAAA=\r\n"), |
| 6097 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6098 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6099 | MockRead("You are not authorized to view this page\r\n"), |
| 6100 | |
| 6101 | // Lastly we get the desired content. |
| 6102 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6103 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6104 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6105 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6106 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6107 | }; |
| 6108 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6109 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6110 | data_writes1, arraysize(data_writes1)); |
| 6111 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6112 | data_writes2, arraysize(data_writes2)); |
| 6113 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6114 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6115 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6116 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6117 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6119 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6122 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6123 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6125 | |
| 6126 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6129 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6131 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6132 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6133 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6135 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6136 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6137 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6138 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6139 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6141 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6142 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6143 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6146 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6147 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6149 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6150 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6151 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6154 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6155 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6157 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6158 | |
| 6159 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6160 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6161 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6163 | |
| 6164 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6165 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6167 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6169 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6170 | |
| 6171 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6172 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6174 | |
| 6175 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6178 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6179 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6180 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6181 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6182 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6183 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6184 | // Test reading a server response which has only headers, and no body. |
| 6185 | // After some maximum number of bytes is consumed, the transaction should |
| 6186 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6187 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6188 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6190 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6191 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6193 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6194 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6195 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6196 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6197 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6198 | |
| 6199 | MockRead data_reads[] = { |
| 6200 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6201 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6202 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6203 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6204 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6205 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6206 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6208 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6209 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6210 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6212 | |
| 6213 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6214 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6215 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6216 | |
| 6217 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6218 | // establish tunnel. |
| 6219 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6220 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6221 | HttpRequestInfo request; |
| 6222 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6223 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6224 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6225 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6226 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6227 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6230 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6232 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6233 | // Since we have proxy, should try to establish tunnel. |
| 6234 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6235 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6236 | "Host: www.example.org:443\r\n" |
| 6237 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6238 | }; |
| 6239 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6240 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6241 | // connection. Usually a proxy would return 501 (not implemented), |
| 6242 | // or 200 (tunnel established). |
| 6243 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6244 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6245 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6246 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6247 | }; |
| 6248 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6249 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6250 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6253 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6254 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6255 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6257 | |
| 6258 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6259 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6260 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6261 | // Empty the current queue. This is necessary because idle sockets are |
| 6262 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6263 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6264 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6265 | // We now check to make sure the TCPClientSocket was not added back to |
| 6266 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6267 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6268 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6269 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6270 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6271 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6272 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6273 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6274 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6275 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6276 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6277 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6278 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6279 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6282 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6283 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6284 | MockRead data_reads[] = { |
| 6285 | // A part of the response body is received with the response headers. |
| 6286 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6287 | // The rest of the response body is received in two parts. |
| 6288 | MockRead("lo"), |
| 6289 | MockRead(" world"), |
| 6290 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6291 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6292 | }; |
| 6293 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6294 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6297 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6299 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6301 | |
| 6302 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6304 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6305 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6306 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6307 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6308 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6309 | std::string status_line = response->headers->GetStatusLine(); |
| 6310 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6311 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6312 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6313 | |
| 6314 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6315 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6316 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6317 | EXPECT_EQ("hello world", response_data); |
| 6318 | |
| 6319 | // Empty the current queue. This is necessary because idle sockets are |
| 6320 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6321 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6322 | |
| 6323 | // 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] | 6324 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6325 | } |
| 6326 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6327 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6328 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6329 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6330 | HttpRequestInfo request; |
| 6331 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6332 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6333 | |
| 6334 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6335 | MockWrite( |
| 6336 | "GET / HTTP/1.1\r\n" |
| 6337 | "Host: www.example.org\r\n" |
| 6338 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6339 | }; |
| 6340 | |
| 6341 | MockRead data_reads[] = { |
| 6342 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6343 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6344 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6345 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6346 | }; |
| 6347 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6348 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6350 | |
| 6351 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6352 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6355 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6359 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6360 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6361 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6363 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6365 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6366 | ASSERT_TRUE(response); |
| 6367 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6368 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6369 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6370 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6371 | |
| 6372 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6374 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6375 | EXPECT_EQ("hello world", response_data); |
| 6376 | |
| 6377 | // Empty the current queue. This is necessary because idle sockets are |
| 6378 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6379 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6380 | |
| 6381 | // 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] | 6382 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6386 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6387 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6388 | HttpRequestInfo request; |
| 6389 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6390 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6391 | |
| 6392 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6393 | MockWrite( |
| 6394 | "GET / HTTP/1.1\r\n" |
| 6395 | "Host: www.example.org\r\n" |
| 6396 | "Connection: keep-alive\r\n\r\n"), |
| 6397 | MockWrite( |
| 6398 | "GET / HTTP/1.1\r\n" |
| 6399 | "Host: www.example.org\r\n" |
| 6400 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6401 | }; |
| 6402 | |
| 6403 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6404 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6405 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6406 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6407 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6408 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6411 | |
| 6412 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6413 | data_writes, arraysize(data_writes)); |
| 6414 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6415 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6416 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6417 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6419 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6422 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6424 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6425 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6426 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6428 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6429 | |
| 6430 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6431 | ASSERT_TRUE(response); |
| 6432 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6433 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6434 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6435 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6436 | |
| 6437 | std::string response_data; |
| 6438 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6439 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6440 | EXPECT_EQ("hello world", response_data); |
| 6441 | |
| 6442 | // Empty the current queue. This is necessary because idle sockets are |
| 6443 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6444 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6445 | |
| 6446 | // 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] | 6447 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6448 | |
| 6449 | // Now start the second transaction, which should reuse the previous socket. |
| 6450 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6451 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6452 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6453 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6454 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6456 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6457 | |
| 6458 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6459 | ASSERT_TRUE(response); |
| 6460 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6461 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6462 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6463 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6464 | |
| 6465 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6467 | EXPECT_EQ("hello world", response_data); |
| 6468 | |
| 6469 | // Empty the current queue. This is necessary because idle sockets are |
| 6470 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6471 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6472 | |
| 6473 | // 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] | 6474 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6475 | } |
| 6476 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6477 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6478 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6479 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6480 | HttpRequestInfo request; |
| 6481 | request.method = "GET"; |
| 6482 | request.url = GURL("http://www.example.org/"); |
| 6483 | request.load_flags = 0; |
| 6484 | |
| 6485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6488 | |
| 6489 | MockRead data_reads[] = { |
| 6490 | // A part of the response body is received with the response headers. |
| 6491 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6492 | // The rest of the response body is received in two parts. |
| 6493 | MockRead("lo"), MockRead(" world"), |
| 6494 | MockRead("junk"), // Should not be read!! |
| 6495 | MockRead(SYNCHRONOUS, OK), |
| 6496 | }; |
| 6497 | |
| 6498 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6499 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6500 | |
| 6501 | TestCompletionCallback callback; |
| 6502 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6503 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6505 | |
| 6506 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6508 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6509 | ASSERT_TRUE(response); |
| 6510 | EXPECT_TRUE(response->headers); |
| 6511 | std::string status_line = response->headers->GetStatusLine(); |
| 6512 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6513 | |
| 6514 | // Make memory critical notification and ensure the transaction still has been |
| 6515 | // operating right. |
| 6516 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6517 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6518 | base::RunLoop().RunUntilIdle(); |
| 6519 | |
| 6520 | // Socket should not be flushed as long as it is not idle. |
| 6521 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6522 | |
| 6523 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6524 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6525 | EXPECT_THAT(rv, IsOk()); |
| 6526 | EXPECT_EQ("hello world", response_data); |
| 6527 | |
| 6528 | // Empty the current queue. This is necessary because idle sockets are |
| 6529 | // added to the connection pool asynchronously with a PostTask. |
| 6530 | base::RunLoop().RunUntilIdle(); |
| 6531 | |
| 6532 | // We now check to make sure the socket was added back to the pool. |
| 6533 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6534 | |
| 6535 | // Idle sockets should be flushed now. |
| 6536 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6537 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6538 | base::RunLoop().RunUntilIdle(); |
| 6539 | |
| 6540 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6541 | } |
| 6542 | |
| 6543 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6544 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6545 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6546 | HttpRequestInfo request; |
| 6547 | request.method = "GET"; |
| 6548 | request.url = GURL("https://www.example.org/"); |
| 6549 | request.load_flags = 0; |
| 6550 | |
| 6551 | MockWrite data_writes[] = { |
| 6552 | MockWrite("GET / HTTP/1.1\r\n" |
| 6553 | "Host: www.example.org\r\n" |
| 6554 | "Connection: keep-alive\r\n\r\n"), |
| 6555 | }; |
| 6556 | |
| 6557 | MockRead data_reads[] = { |
| 6558 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6559 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6560 | |
| 6561 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6563 | |
| 6564 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6565 | arraysize(data_writes)); |
| 6566 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6567 | |
| 6568 | TestCompletionCallback callback; |
| 6569 | |
| 6570 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6571 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6572 | |
| 6573 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6574 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6575 | |
| 6576 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6578 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6579 | ASSERT_TRUE(response); |
| 6580 | ASSERT_TRUE(response->headers); |
| 6581 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6582 | |
| 6583 | // Make memory critical notification and ensure the transaction still has been |
| 6584 | // operating right. |
| 6585 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6586 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6587 | base::RunLoop().RunUntilIdle(); |
| 6588 | |
| 6589 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6590 | |
| 6591 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6592 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6593 | EXPECT_THAT(rv, IsOk()); |
| 6594 | EXPECT_EQ("hello world", response_data); |
| 6595 | |
| 6596 | // Empty the current queue. This is necessary because idle sockets are |
| 6597 | // added to the connection pool asynchronously with a PostTask. |
| 6598 | base::RunLoop().RunUntilIdle(); |
| 6599 | |
| 6600 | // We now check to make sure the socket was added back to the pool. |
| 6601 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6602 | |
| 6603 | // Make memory notification once again and ensure idle socket is closed. |
| 6604 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6605 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6606 | base::RunLoop().RunUntilIdle(); |
| 6607 | |
| 6608 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6609 | } |
| 6610 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6611 | // Make sure that we recycle a socket after a zero-length response. |
| 6612 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6613 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6614 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6616 | request.url = GURL( |
| 6617 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6618 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6619 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6620 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6621 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6623 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6624 | MockRead data_reads[] = { |
| 6625 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6626 | "Content-Length: 0\r\n" |
| 6627 | "Content-Type: text/html\r\n\r\n"), |
| 6628 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6630 | }; |
| 6631 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6632 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6633 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6634 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6635 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6636 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6639 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6640 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6641 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6643 | |
| 6644 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6645 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6647 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6648 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6649 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6650 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6651 | std::string status_line = response->headers->GetStatusLine(); |
| 6652 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6653 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6654 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6655 | |
| 6656 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6657 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6658 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6659 | EXPECT_EQ("", response_data); |
| 6660 | |
| 6661 | // Empty the current queue. This is necessary because idle sockets are |
| 6662 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6663 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6664 | |
| 6665 | // 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] | 6666 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6667 | } |
| 6668 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6669 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6670 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6671 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6672 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6673 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6674 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6675 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6676 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6677 | // after use. |
| 6678 | request[0].method = "GET"; |
| 6679 | request[0].url = GURL("http://www.google.com/"); |
| 6680 | request[0].load_flags = 0; |
| 6681 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6682 | // transaction 1. The first attempts fails when writing the POST data. |
| 6683 | // This causes the transaction to retry with a new socket. The second |
| 6684 | // attempt succeeds. |
| 6685 | request[1].method = "POST"; |
| 6686 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6687 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6688 | request[1].load_flags = 0; |
| 6689 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6691 | |
| 6692 | // The first socket is used for transaction 1 and the first attempt of |
| 6693 | // transaction 2. |
| 6694 | |
| 6695 | // The response of transaction 1. |
| 6696 | MockRead data_reads1[] = { |
| 6697 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6698 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6699 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6700 | }; |
| 6701 | // The mock write results of transaction 1 and the first attempt of |
| 6702 | // transaction 2. |
| 6703 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6704 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6705 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6706 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6707 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6708 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6709 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6710 | |
| 6711 | // The second socket is used for the second attempt of transaction 2. |
| 6712 | |
| 6713 | // The response of transaction 2. |
| 6714 | MockRead data_reads2[] = { |
| 6715 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6716 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6717 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6718 | }; |
| 6719 | // The mock write results of the second attempt of transaction 2. |
| 6720 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6721 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6722 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6723 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6724 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6725 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6726 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6727 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6728 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6729 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6730 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6731 | "hello world", "welcome" |
| 6732 | }; |
| 6733 | |
| 6734 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6737 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6739 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6741 | |
| 6742 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6746 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6747 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6748 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6749 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6750 | |
| 6751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6752 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6754 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6755 | } |
| 6756 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6757 | |
| 6758 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6759 | // 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] | 6760 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6761 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6762 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6764 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6765 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6769 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6770 | // The password contains an escaped character -- for this test to pass it |
| 6771 | // will need to be unescaped by HttpNetworkTransaction. |
| 6772 | EXPECT_EQ("b%40r", request.url.password()); |
| 6773 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6774 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6775 | MockWrite( |
| 6776 | "GET / HTTP/1.1\r\n" |
| 6777 | "Host: www.example.org\r\n" |
| 6778 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6779 | }; |
| 6780 | |
| 6781 | MockRead data_reads1[] = { |
| 6782 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6783 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6784 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6785 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6786 | }; |
| 6787 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6788 | // After the challenge above, the transaction will be restarted using the |
| 6789 | // identity from the url (foo, b@r) to answer the challenge. |
| 6790 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6791 | MockWrite( |
| 6792 | "GET / HTTP/1.1\r\n" |
| 6793 | "Host: www.example.org\r\n" |
| 6794 | "Connection: keep-alive\r\n" |
| 6795 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6796 | }; |
| 6797 | |
| 6798 | MockRead data_reads2[] = { |
| 6799 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6800 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6801 | MockRead(SYNCHRONOUS, OK), |
| 6802 | }; |
| 6803 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6804 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6805 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6806 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6807 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6808 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6809 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6812 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6814 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6815 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6816 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6817 | |
| 6818 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6819 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6821 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6822 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6823 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6825 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6826 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6827 | |
| 6828 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6829 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6830 | |
| 6831 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6832 | |
| 6833 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6834 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6838 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6839 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6841 | HttpRequestInfo request; |
| 6842 | request.method = "GET"; |
| 6843 | // Note: the URL has a username:password in it. The password "baz" is |
| 6844 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6845 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6846 | |
| 6847 | request.load_flags = LOAD_NORMAL; |
| 6848 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6850 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6851 | |
| 6852 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6853 | MockWrite( |
| 6854 | "GET / HTTP/1.1\r\n" |
| 6855 | "Host: www.example.org\r\n" |
| 6856 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6857 | }; |
| 6858 | |
| 6859 | MockRead data_reads1[] = { |
| 6860 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6861 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6862 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6863 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6864 | }; |
| 6865 | |
| 6866 | // After the challenge above, the transaction will be restarted using the |
| 6867 | // identity from the url (foo, baz) to answer the challenge. |
| 6868 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6869 | MockWrite( |
| 6870 | "GET / HTTP/1.1\r\n" |
| 6871 | "Host: www.example.org\r\n" |
| 6872 | "Connection: keep-alive\r\n" |
| 6873 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6874 | }; |
| 6875 | |
| 6876 | MockRead data_reads2[] = { |
| 6877 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6878 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6879 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6880 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6881 | }; |
| 6882 | |
| 6883 | // After the challenge above, the transaction will be restarted using the |
| 6884 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6885 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6886 | MockWrite( |
| 6887 | "GET / HTTP/1.1\r\n" |
| 6888 | "Host: www.example.org\r\n" |
| 6889 | "Connection: keep-alive\r\n" |
| 6890 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6891 | }; |
| 6892 | |
| 6893 | MockRead data_reads3[] = { |
| 6894 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6895 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6896 | MockRead(SYNCHRONOUS, OK), |
| 6897 | }; |
| 6898 | |
| 6899 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6900 | data_writes1, arraysize(data_writes1)); |
| 6901 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6902 | data_writes2, arraysize(data_writes2)); |
| 6903 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6904 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6905 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6906 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6907 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6908 | |
| 6909 | TestCompletionCallback callback1; |
| 6910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6911 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6913 | |
| 6914 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6915 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6917 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6918 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6919 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6921 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6922 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6923 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6926 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6927 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6928 | |
| 6929 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6930 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6932 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6933 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6934 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6936 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6937 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6938 | |
| 6939 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6940 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6941 | |
| 6942 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6943 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6944 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6945 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6946 | } |
| 6947 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6948 | |
| 6949 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6950 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6951 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6952 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6953 | HttpRequestInfo request; |
| 6954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6955 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6956 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6957 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6959 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6960 | |
| 6961 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6962 | MockWrite( |
| 6963 | "GET / HTTP/1.1\r\n" |
| 6964 | "Host: www.example.org\r\n" |
| 6965 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6966 | }; |
| 6967 | |
| 6968 | MockRead data_reads1[] = { |
| 6969 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6970 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6971 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6972 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6973 | }; |
| 6974 | |
| 6975 | // After the challenge above, the transaction will be restarted using the |
| 6976 | // identity supplied by the user, not the one in the URL, to answer the |
| 6977 | // challenge. |
| 6978 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6979 | MockWrite( |
| 6980 | "GET / HTTP/1.1\r\n" |
| 6981 | "Host: www.example.org\r\n" |
| 6982 | "Connection: keep-alive\r\n" |
| 6983 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6984 | }; |
| 6985 | |
| 6986 | MockRead data_reads3[] = { |
| 6987 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6988 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6989 | MockRead(SYNCHRONOUS, OK), |
| 6990 | }; |
| 6991 | |
| 6992 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6993 | data_writes1, arraysize(data_writes1)); |
| 6994 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6995 | data_writes3, arraysize(data_writes3)); |
| 6996 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6997 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6998 | |
| 6999 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7000 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7002 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7003 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7004 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7007 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7008 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7009 | |
| 7010 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7011 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7013 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7014 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7015 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7017 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7018 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7019 | |
| 7020 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7021 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7022 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7023 | |
| 7024 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7025 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7026 | } |
| 7027 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7028 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7029 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7031 | |
| 7032 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7033 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7034 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7036 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7038 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7039 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7040 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7041 | MockWrite( |
| 7042 | "GET /x/y/z HTTP/1.1\r\n" |
| 7043 | "Host: www.example.org\r\n" |
| 7044 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7045 | }; |
| 7046 | |
| 7047 | MockRead data_reads1[] = { |
| 7048 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7049 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7050 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7051 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7052 | }; |
| 7053 | |
| 7054 | // Resend with authorization (username=foo, password=bar) |
| 7055 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7056 | MockWrite( |
| 7057 | "GET /x/y/z HTTP/1.1\r\n" |
| 7058 | "Host: www.example.org\r\n" |
| 7059 | "Connection: keep-alive\r\n" |
| 7060 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7061 | }; |
| 7062 | |
| 7063 | // Sever accepts the authorization. |
| 7064 | MockRead data_reads2[] = { |
| 7065 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7066 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7067 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7068 | }; |
| 7069 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7070 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7071 | data_writes1, arraysize(data_writes1)); |
| 7072 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7073 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7074 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7075 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7077 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7079 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7081 | |
| 7082 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7085 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7086 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7087 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7089 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7091 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7092 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7094 | |
| 7095 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7098 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7099 | ASSERT_TRUE(response); |
| 7100 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7101 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7102 | } |
| 7103 | |
| 7104 | // ------------------------------------------------------------------------ |
| 7105 | |
| 7106 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7107 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7108 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7109 | request.method = "GET"; |
| 7110 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7111 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7112 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7115 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7116 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7117 | MockWrite( |
| 7118 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7119 | "Host: www.example.org\r\n" |
| 7120 | "Connection: keep-alive\r\n" |
| 7121 | // Send preemptive authorization for MyRealm1 |
| 7122 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7123 | }; |
| 7124 | |
| 7125 | // The server didn't like the preemptive authorization, and |
| 7126 | // challenges us for a different realm (MyRealm2). |
| 7127 | MockRead data_reads1[] = { |
| 7128 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7129 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7130 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7131 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7132 | }; |
| 7133 | |
| 7134 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7135 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7136 | MockWrite( |
| 7137 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7138 | "Host: www.example.org\r\n" |
| 7139 | "Connection: keep-alive\r\n" |
| 7140 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7141 | }; |
| 7142 | |
| 7143 | // Sever accepts the authorization. |
| 7144 | MockRead data_reads2[] = { |
| 7145 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7146 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7147 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7148 | }; |
| 7149 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7150 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7151 | data_writes1, arraysize(data_writes1)); |
| 7152 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7153 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7154 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7155 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7157 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7159 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7161 | |
| 7162 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7165 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7166 | ASSERT_TRUE(response); |
| 7167 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7168 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7169 | EXPECT_EQ("http://www.example.org", |
| 7170 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7171 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7172 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7174 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7176 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7177 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7179 | |
| 7180 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7181 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7183 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7184 | ASSERT_TRUE(response); |
| 7185 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7186 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7187 | } |
| 7188 | |
| 7189 | // ------------------------------------------------------------------------ |
| 7190 | |
| 7191 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7192 | // succeed with preemptive authorization. |
| 7193 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7194 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7195 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7196 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7198 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7199 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7200 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7201 | MockWrite( |
| 7202 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7203 | "Host: www.example.org\r\n" |
| 7204 | "Connection: keep-alive\r\n" |
| 7205 | // The authorization for MyRealm1 gets sent preemptively |
| 7206 | // (since the url is in the same protection space) |
| 7207 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7208 | }; |
| 7209 | |
| 7210 | // Sever accepts the preemptive authorization |
| 7211 | MockRead data_reads1[] = { |
| 7212 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7213 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7214 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7215 | }; |
| 7216 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7217 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7218 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7221 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7222 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7223 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7225 | |
| 7226 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7227 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7229 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7230 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7231 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7232 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7233 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7234 | } |
| 7235 | |
| 7236 | // ------------------------------------------------------------------------ |
| 7237 | |
| 7238 | // Transaction 4: request another URL in MyRealm (however the |
| 7239 | // url is not known to belong to the protection space, so no pre-auth). |
| 7240 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7241 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7242 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7243 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7246 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7247 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7248 | MockWrite( |
| 7249 | "GET /x/1 HTTP/1.1\r\n" |
| 7250 | "Host: www.example.org\r\n" |
| 7251 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7252 | }; |
| 7253 | |
| 7254 | MockRead data_reads1[] = { |
| 7255 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7256 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7257 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7258 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7259 | }; |
| 7260 | |
| 7261 | // Resend with authorization from MyRealm's cache. |
| 7262 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7263 | MockWrite( |
| 7264 | "GET /x/1 HTTP/1.1\r\n" |
| 7265 | "Host: www.example.org\r\n" |
| 7266 | "Connection: keep-alive\r\n" |
| 7267 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7268 | }; |
| 7269 | |
| 7270 | // Sever accepts the authorization. |
| 7271 | MockRead data_reads2[] = { |
| 7272 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7273 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7274 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7275 | }; |
| 7276 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7277 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7278 | data_writes1, arraysize(data_writes1)); |
| 7279 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7280 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7281 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7282 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7284 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7285 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7286 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7288 | |
| 7289 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7290 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7293 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7294 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7296 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7297 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7298 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7300 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7301 | ASSERT_TRUE(response); |
| 7302 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7303 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7304 | } |
| 7305 | |
| 7306 | // ------------------------------------------------------------------------ |
| 7307 | |
| 7308 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7309 | // cached identity. Should invalidate and re-prompt. |
| 7310 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7311 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7313 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7315 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7316 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7317 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7318 | MockWrite( |
| 7319 | "GET /p/q/t HTTP/1.1\r\n" |
| 7320 | "Host: www.example.org\r\n" |
| 7321 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7322 | }; |
| 7323 | |
| 7324 | MockRead data_reads1[] = { |
| 7325 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7326 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7327 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7328 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7329 | }; |
| 7330 | |
| 7331 | // Resend with authorization from cache for MyRealm. |
| 7332 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7333 | MockWrite( |
| 7334 | "GET /p/q/t HTTP/1.1\r\n" |
| 7335 | "Host: www.example.org\r\n" |
| 7336 | "Connection: keep-alive\r\n" |
| 7337 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7338 | }; |
| 7339 | |
| 7340 | // Sever rejects the authorization. |
| 7341 | MockRead data_reads2[] = { |
| 7342 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7343 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7344 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7345 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7346 | }; |
| 7347 | |
| 7348 | // At this point we should prompt for new credentials for MyRealm. |
| 7349 | // Restart with username=foo3, password=foo4. |
| 7350 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7351 | MockWrite( |
| 7352 | "GET /p/q/t HTTP/1.1\r\n" |
| 7353 | "Host: www.example.org\r\n" |
| 7354 | "Connection: keep-alive\r\n" |
| 7355 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7356 | }; |
| 7357 | |
| 7358 | // Sever accepts the authorization. |
| 7359 | MockRead data_reads3[] = { |
| 7360 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7361 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7362 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7363 | }; |
| 7364 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7365 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7366 | data_writes1, arraysize(data_writes1)); |
| 7367 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7368 | data_writes2, arraysize(data_writes2)); |
| 7369 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7370 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7371 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7373 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7375 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7376 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7377 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7379 | |
| 7380 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7381 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7384 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7385 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7387 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7388 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7392 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7393 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7395 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7397 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7398 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7400 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7401 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7402 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7404 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7405 | ASSERT_TRUE(response); |
| 7406 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7407 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7408 | } |
| 7409 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7410 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7411 | // Tests that nonce count increments when multiple auth attempts |
| 7412 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7413 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7414 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7415 | new HttpAuthHandlerDigest::Factory(); |
| 7416 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7417 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7418 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7419 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7420 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7421 | |
| 7422 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7423 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7424 | HttpRequestInfo request; |
| 7425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7429 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7430 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7431 | MockWrite( |
| 7432 | "GET /x/y/z HTTP/1.1\r\n" |
| 7433 | "Host: www.example.org\r\n" |
| 7434 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7435 | }; |
| 7436 | |
| 7437 | MockRead data_reads1[] = { |
| 7438 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7439 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7440 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7441 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7442 | }; |
| 7443 | |
| 7444 | // Resend with authorization (username=foo, password=bar) |
| 7445 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7446 | MockWrite( |
| 7447 | "GET /x/y/z HTTP/1.1\r\n" |
| 7448 | "Host: www.example.org\r\n" |
| 7449 | "Connection: keep-alive\r\n" |
| 7450 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7451 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7452 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7453 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7454 | }; |
| 7455 | |
| 7456 | // Sever accepts the authorization. |
| 7457 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7458 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7459 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7460 | }; |
| 7461 | |
| 7462 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7463 | data_writes1, arraysize(data_writes1)); |
| 7464 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7465 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7467 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7469 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7471 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7473 | |
| 7474 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7478 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7479 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7481 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7483 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7484 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7486 | |
| 7487 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7490 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7491 | ASSERT_TRUE(response); |
| 7492 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | // ------------------------------------------------------------------------ |
| 7496 | |
| 7497 | // Transaction 2: Request another resource in digestive's protection space. |
| 7498 | // This will preemptively add an Authorization header which should have an |
| 7499 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7500 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7501 | HttpRequestInfo request; |
| 7502 | request.method = "GET"; |
| 7503 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7504 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7505 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7508 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7510 | MockWrite( |
| 7511 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7512 | "Host: www.example.org\r\n" |
| 7513 | "Connection: keep-alive\r\n" |
| 7514 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7515 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7516 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7517 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7518 | }; |
| 7519 | |
| 7520 | // Sever accepts the authorization. |
| 7521 | MockRead data_reads1[] = { |
| 7522 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7523 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7524 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7525 | }; |
| 7526 | |
| 7527 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7528 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7529 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7531 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7532 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7533 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7535 | |
| 7536 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7537 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7539 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7540 | ASSERT_TRUE(response); |
| 7541 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7542 | } |
| 7543 | } |
| 7544 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7545 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7546 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7547 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7549 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7550 | |
| 7551 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7552 | trans.read_buf_ = new IOBuffer(15); |
| 7553 | trans.read_buf_len_ = 15; |
| 7554 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7555 | |
| 7556 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7557 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7558 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7559 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7560 | response->response_time = base::Time::Now(); |
| 7561 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7562 | |
| 7563 | { // Setup state for response_.vary_data |
| 7564 | HttpRequestInfo request; |
| 7565 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7566 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7567 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7568 | request.extra_headers.SetHeader("Foo", "1"); |
| 7569 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7570 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7571 | } |
| 7572 | |
| 7573 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7574 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7575 | |
| 7576 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7577 | EXPECT_FALSE(trans.read_buf_); |
| 7578 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7579 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7580 | EXPECT_FALSE(response->auth_challenge); |
| 7581 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7582 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7583 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7584 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7585 | } |
| 7586 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7587 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7588 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7589 | HttpRequestInfo request; |
| 7590 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7591 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7595 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7596 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7597 | MockWrite( |
| 7598 | "GET / HTTP/1.1\r\n" |
| 7599 | "Host: www.example.org\r\n" |
| 7600 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7601 | }; |
| 7602 | |
| 7603 | MockRead data_reads[] = { |
| 7604 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7605 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7606 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7608 | }; |
| 7609 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7610 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7612 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7613 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7614 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7615 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7616 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7617 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7621 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7625 | |
| 7626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7627 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7629 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7631 | |
| 7632 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7633 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7635 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7636 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7637 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7638 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7639 | } |
| 7640 | |
| 7641 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7642 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7643 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7644 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7645 | |
| 7646 | HttpRequestInfo request; |
| 7647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7648 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7649 | |
| 7650 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7651 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7652 | "Host: www.example.org:443\r\n" |
| 7653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7654 | }; |
| 7655 | |
| 7656 | MockRead proxy_reads[] = { |
| 7657 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7658 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7659 | }; |
| 7660 | |
| 7661 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7662 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7663 | "Host: www.example.org:443\r\n" |
| 7664 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7665 | MockWrite("GET / HTTP/1.1\r\n" |
| 7666 | "Host: www.example.org\r\n" |
| 7667 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7668 | }; |
| 7669 | |
| 7670 | MockRead data_reads[] = { |
| 7671 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7672 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7673 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7674 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7675 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7676 | }; |
| 7677 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7678 | StaticSocketDataProvider ssl_bad_certificate( |
| 7679 | proxy_reads, arraysize(proxy_reads), |
| 7680 | proxy_writes, arraysize(proxy_writes)); |
| 7681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7682 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7683 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7684 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7685 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7686 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7688 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7691 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7692 | |
| 7693 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7694 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7701 | |
| 7702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7703 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7705 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7707 | |
| 7708 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7709 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7711 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7712 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7713 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7714 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7715 | } |
| 7716 | } |
| 7717 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7718 | |
| 7719 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7720 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7721 | session_deps_.proxy_service = |
| 7722 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7723 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7724 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7725 | |
| 7726 | HttpRequestInfo request; |
| 7727 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7728 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7729 | |
| 7730 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7732 | "Host: www.example.org:443\r\n" |
| 7733 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7734 | MockWrite("GET / HTTP/1.1\r\n" |
| 7735 | "Host: www.example.org\r\n" |
| 7736 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7737 | }; |
| 7738 | |
| 7739 | MockRead data_reads[] = { |
| 7740 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7741 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7742 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7743 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7744 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7745 | }; |
| 7746 | |
| 7747 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7748 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7749 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7750 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7751 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7756 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7760 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7761 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7763 | |
| 7764 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7765 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7766 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7767 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7768 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7769 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7770 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7771 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7772 | EXPECT_EQ(200, response->headers->response_code()); |
| 7773 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7774 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7775 | |
| 7776 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7777 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7778 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7779 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7780 | } |
| 7781 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7782 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7783 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7784 | session_deps_.proxy_service = |
| 7785 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7787 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7788 | |
| 7789 | HttpRequestInfo request; |
| 7790 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7791 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7792 | |
| 7793 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7794 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7795 | "Host: www.example.org:443\r\n" |
| 7796 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7797 | }; |
| 7798 | |
| 7799 | MockRead data_reads[] = { |
| 7800 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7801 | MockRead("Location: http://login.example.com/\r\n"), |
| 7802 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7804 | }; |
| 7805 | |
| 7806 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7807 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7808 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7809 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7811 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7813 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7818 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7820 | |
| 7821 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7822 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7823 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7824 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7825 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7826 | |
| 7827 | EXPECT_EQ(302, response->headers->response_code()); |
| 7828 | std::string url; |
| 7829 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7830 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7831 | |
| 7832 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7833 | // timing for the proxy connection instead of the connection to the host, |
| 7834 | // and no send / receive times. |
| 7835 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7836 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7837 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7838 | |
| 7839 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7840 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7841 | |
| 7842 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7843 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7844 | load_timing_info.proxy_resolve_end); |
| 7845 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7846 | load_timing_info.connect_timing.connect_start); |
| 7847 | ExpectConnectTimingHasTimes( |
| 7848 | load_timing_info.connect_timing, |
| 7849 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7850 | |
| 7851 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7852 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7853 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7854 | } |
| 7855 | |
| 7856 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7857 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7858 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7859 | |
| 7860 | HttpRequestInfo request; |
| 7861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7862 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7863 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7864 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7865 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7866 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame^] | 7867 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7868 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7869 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7870 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7871 | }; |
| 7872 | |
| 7873 | static const char* const kExtraHeaders[] = { |
| 7874 | "location", |
| 7875 | "http://login.example.com/", |
| 7876 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7877 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7878 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7879 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7880 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7881 | }; |
| 7882 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7883 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7884 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7885 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7886 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7887 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7888 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7891 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7892 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7894 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7896 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7898 | |
| 7899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7900 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7901 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7902 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7903 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7904 | |
| 7905 | EXPECT_EQ(302, response->headers->response_code()); |
| 7906 | std::string url; |
| 7907 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7908 | EXPECT_EQ("http://login.example.com/", url); |
| 7909 | } |
| 7910 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7911 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7912 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7913 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7914 | |
| 7915 | HttpRequestInfo request; |
| 7916 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7917 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7918 | |
| 7919 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7920 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7921 | "Host: www.example.org:443\r\n" |
| 7922 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7923 | }; |
| 7924 | |
| 7925 | MockRead data_reads[] = { |
| 7926 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7927 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7928 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7930 | }; |
| 7931 | |
| 7932 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7933 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7934 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7935 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7939 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7940 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7942 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7946 | |
| 7947 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7948 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7949 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7950 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7951 | } |
| 7952 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7953 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7954 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7955 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7956 | |
| 7957 | HttpRequestInfo request; |
| 7958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7959 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7960 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7962 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7963 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame^] | 7964 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7965 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7966 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7967 | }; |
| 7968 | |
| 7969 | static const char* const kExtraHeaders[] = { |
| 7970 | "location", |
| 7971 | "http://login.example.com/", |
| 7972 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7973 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7974 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7975 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7976 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7977 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7978 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7979 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7980 | }; |
| 7981 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7982 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7983 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7984 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7985 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7986 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7990 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7995 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7997 | |
| 7998 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7999 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8000 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8001 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8002 | } |
| 8003 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8004 | // Test the request-challenge-retry sequence for basic auth, through |
| 8005 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8006 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8007 | HttpRequestInfo request; |
| 8008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8009 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8010 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8011 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8012 | |
| 8013 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8014 | session_deps_.proxy_service = |
| 8015 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8016 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8017 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8019 | |
| 8020 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8021 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8022 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8023 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame^] | 8024 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8025 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8027 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8028 | // be issuing -- the final header line contains the credentials. |
| 8029 | const char* const kAuthCredentials[] = { |
| 8030 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8031 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8032 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8033 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8034 | HostPortPair("www.example.org", 443))); |
| 8035 | // fetch https://www.example.org/ via HTTP |
| 8036 | const char get[] = |
| 8037 | "GET / HTTP/1.1\r\n" |
| 8038 | "Host: www.example.org\r\n" |
| 8039 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8040 | SpdySerializedFrame wrapped_get( |
| 8041 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8042 | |
| 8043 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8044 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8045 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8046 | }; |
| 8047 | |
| 8048 | // The proxy responds to the connect with a 407, using a persistent |
| 8049 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8050 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8051 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8052 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8053 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8054 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8055 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8056 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8057 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8058 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8059 | "Content-Length: 5\r\n\r\n"; |
| 8060 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8061 | SpdySerializedFrame wrapped_get_resp( |
| 8062 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8063 | SpdySerializedFrame wrapped_body( |
| 8064 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8065 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8066 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8067 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8068 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8069 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8070 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8071 | }; |
| 8072 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8073 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8074 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8075 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8076 | // Negotiate SPDY to the proxy |
| 8077 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8078 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8080 | // Vanilla SSL to the server |
| 8081 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8082 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8083 | |
| 8084 | TestCompletionCallback callback1; |
| 8085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8086 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8087 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8088 | |
| 8089 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8091 | |
| 8092 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8093 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8094 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8095 | log.GetEntries(&entries); |
| 8096 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8097 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8098 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8099 | ExpectLogContainsSomewhere( |
| 8100 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8101 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8102 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8103 | |
| 8104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8105 | ASSERT_TRUE(response); |
| 8106 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8107 | EXPECT_EQ(407, response->headers->response_code()); |
| 8108 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8109 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8110 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8111 | |
| 8112 | TestCompletionCallback callback2; |
| 8113 | |
| 8114 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8115 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8117 | |
| 8118 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8120 | |
| 8121 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8122 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8123 | |
| 8124 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8125 | EXPECT_EQ(200, response->headers->response_code()); |
| 8126 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8127 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8128 | |
| 8129 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8130 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8131 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8132 | LoadTimingInfo load_timing_info; |
| 8133 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8134 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8135 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8136 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8137 | trans.reset(); |
| 8138 | session->CloseAllConnections(); |
| 8139 | } |
| 8140 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8141 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8142 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8143 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8144 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8145 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8146 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8147 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8148 | HttpRequestInfo request; |
| 8149 | HttpRequestInfo push_request; |
| 8150 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8151 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8152 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8153 | push_request.method = "GET"; |
| 8154 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8155 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8156 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8157 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8158 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8159 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8160 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8161 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8162 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8163 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8164 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8165 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8166 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8167 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8168 | SpdySerializedFrame stream2_priority( |
| 8169 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8170 | |
| 8171 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8172 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8173 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8174 | }; |
| 8175 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8176 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8177 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8178 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8179 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8180 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8181 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8182 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8183 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8184 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8185 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8186 | |
| 8187 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8188 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8189 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8190 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8191 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8192 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8193 | }; |
| 8194 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8195 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8196 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8197 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8198 | // Negotiate SPDY to the proxy |
| 8199 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8200 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8203 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8205 | TestCompletionCallback callback; |
| 8206 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8208 | |
| 8209 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8210 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8211 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8213 | std::unique_ptr<HttpNetworkTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8214 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8215 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8217 | |
| 8218 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8220 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8221 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8222 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8223 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8224 | |
| 8225 | EXPECT_EQ(200, response->headers->response_code()); |
| 8226 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8227 | |
| 8228 | std::string response_data; |
| 8229 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8231 | EXPECT_EQ("hello!", response_data); |
| 8232 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8233 | LoadTimingInfo load_timing_info; |
| 8234 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8235 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8236 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8237 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8238 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8239 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8240 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8241 | |
| 8242 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8243 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8244 | EXPECT_EQ("pushed", response_data); |
| 8245 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8246 | LoadTimingInfo push_load_timing_info; |
| 8247 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8248 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8249 | // The transactions should share a socket ID, despite being for different |
| 8250 | // origins. |
| 8251 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8252 | push_load_timing_info.socket_log_id); |
| 8253 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8254 | trans.reset(); |
| 8255 | push_trans.reset(); |
| 8256 | session->CloseAllConnections(); |
| 8257 | } |
| 8258 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8259 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8260 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8261 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8262 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8263 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8264 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8265 | HttpRequestInfo request; |
| 8266 | |
| 8267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8268 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8269 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8270 | session_deps_.proxy_service = |
| 8271 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8272 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8273 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8274 | |
| 8275 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8276 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8277 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8279 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8280 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8281 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8282 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8283 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame^] | 8284 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8285 | |
| 8286 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8287 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8288 | }; |
| 8289 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8290 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8291 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8292 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8293 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8294 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8295 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8296 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8297 | |
| 8298 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8299 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8300 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8301 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8302 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8303 | }; |
| 8304 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8305 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8306 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8307 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8308 | // Negotiate SPDY to the proxy |
| 8309 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8310 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8311 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8313 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8314 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8315 | TestCompletionCallback callback; |
| 8316 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8318 | |
| 8319 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8320 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8321 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8322 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8323 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8324 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8325 | |
| 8326 | EXPECT_EQ(200, response->headers->response_code()); |
| 8327 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8328 | |
| 8329 | std::string response_data; |
| 8330 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8331 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8332 | EXPECT_EQ("hello!", response_data); |
| 8333 | |
| 8334 | trans.reset(); |
| 8335 | session->CloseAllConnections(); |
| 8336 | } |
| 8337 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8338 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8339 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8340 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8341 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8342 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8343 | proxy_delegate->set_trusted_spdy_proxy( |
| 8344 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8345 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8346 | HttpRequestInfo request; |
| 8347 | |
| 8348 | request.method = "GET"; |
| 8349 | request.url = GURL("http://www.example.org/"); |
| 8350 | |
| 8351 | // Configure against https proxy server "myproxy:70". |
| 8352 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8353 | BoundTestNetLog log; |
| 8354 | session_deps_.net_log = log.bound().net_log(); |
| 8355 | |
| 8356 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8357 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8360 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8361 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8362 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8363 | SpdySerializedFrame stream2_priority( |
| 8364 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8365 | |
| 8366 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8367 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8368 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8369 | }; |
| 8370 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8371 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8372 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8373 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8374 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8375 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8376 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8377 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8378 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8379 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8380 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8381 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8382 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8383 | |
| 8384 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8385 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8386 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8387 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8388 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8389 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8390 | }; |
| 8391 | |
| 8392 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8393 | arraysize(spdy_writes)); |
| 8394 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8395 | // Negotiate SPDY to the proxy |
| 8396 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8397 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8400 | std::unique_ptr<HttpNetworkTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8401 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8402 | TestCompletionCallback callback; |
| 8403 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8404 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8405 | |
| 8406 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8407 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8408 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8409 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8410 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8411 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8412 | |
| 8413 | EXPECT_EQ(200, response->headers->response_code()); |
| 8414 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8415 | |
| 8416 | std::string response_data; |
| 8417 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8418 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8419 | EXPECT_EQ("hello!", response_data); |
| 8420 | |
| 8421 | trans.reset(); |
| 8422 | session->CloseAllConnections(); |
| 8423 | } |
| 8424 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8425 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8426 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8427 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8428 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8429 | |
| 8430 | HttpRequestInfo request; |
| 8431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8432 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8433 | |
| 8434 | // Attempt to fetch the URL from a server with a bad cert |
| 8435 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8436 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8437 | "Host: www.example.org:443\r\n" |
| 8438 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8439 | }; |
| 8440 | |
| 8441 | MockRead bad_cert_reads[] = { |
| 8442 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8443 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8444 | }; |
| 8445 | |
| 8446 | // Attempt to fetch the URL with a good cert |
| 8447 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8448 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8449 | "Host: www.example.org:443\r\n" |
| 8450 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8451 | MockWrite("GET / HTTP/1.1\r\n" |
| 8452 | "Host: www.example.org\r\n" |
| 8453 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8454 | }; |
| 8455 | |
| 8456 | MockRead good_cert_reads[] = { |
| 8457 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8458 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8459 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8460 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8462 | }; |
| 8463 | |
| 8464 | StaticSocketDataProvider ssl_bad_certificate( |
| 8465 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8466 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8467 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8468 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8469 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8470 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8471 | |
| 8472 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8474 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8476 | |
| 8477 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8482 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8483 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8486 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8487 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8488 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8489 | |
| 8490 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8491 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8493 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8495 | |
| 8496 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8499 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8500 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8501 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8502 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8503 | } |
| 8504 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8505 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8506 | HttpRequestInfo request; |
| 8507 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8508 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8509 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8510 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8514 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8515 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8516 | MockWrite( |
| 8517 | "GET / HTTP/1.1\r\n" |
| 8518 | "Host: www.example.org\r\n" |
| 8519 | "Connection: keep-alive\r\n" |
| 8520 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8521 | }; |
| 8522 | |
| 8523 | // Lastly, the server responds with the actual content. |
| 8524 | MockRead data_reads[] = { |
| 8525 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8527 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8528 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8529 | }; |
| 8530 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8531 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8532 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8535 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8539 | |
| 8540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8541 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8542 | } |
| 8543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8544 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8545 | HttpRequestInfo request; |
| 8546 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8547 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8548 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8549 | "Chromium Ultra Awesome X Edition"); |
| 8550 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8551 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8554 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8555 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8556 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8557 | "Host: www.example.org:443\r\n" |
| 8558 | "Proxy-Connection: keep-alive\r\n" |
| 8559 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8560 | }; |
| 8561 | MockRead data_reads[] = { |
| 8562 | // Return an error, so the transaction stops here (this test isn't |
| 8563 | // interested in the rest). |
| 8564 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8565 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8566 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8567 | }; |
| 8568 | |
| 8569 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8570 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8571 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8573 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8574 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8575 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8576 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8577 | |
| 8578 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8579 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8580 | } |
| 8581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8582 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8583 | HttpRequestInfo request; |
| 8584 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8585 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8586 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8587 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8588 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8591 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8592 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8593 | MockWrite( |
| 8594 | "GET / HTTP/1.1\r\n" |
| 8595 | "Host: www.example.org\r\n" |
| 8596 | "Connection: keep-alive\r\n" |
| 8597 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8598 | }; |
| 8599 | |
| 8600 | // Lastly, the server responds with the actual content. |
| 8601 | MockRead data_reads[] = { |
| 8602 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8603 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8604 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8606 | }; |
| 8607 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8609 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8612 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8616 | |
| 8617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8619 | } |
| 8620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8621 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8622 | HttpRequestInfo request; |
| 8623 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8624 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8628 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8629 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8630 | MockWrite( |
| 8631 | "POST / HTTP/1.1\r\n" |
| 8632 | "Host: www.example.org\r\n" |
| 8633 | "Connection: keep-alive\r\n" |
| 8634 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8635 | }; |
| 8636 | |
| 8637 | // Lastly, the server responds with the actual content. |
| 8638 | MockRead data_reads[] = { |
| 8639 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8640 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8641 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8642 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8643 | }; |
| 8644 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8645 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8646 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8649 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8651 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8653 | |
| 8654 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8655 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8656 | } |
| 8657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8658 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8659 | HttpRequestInfo request; |
| 8660 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8661 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8665 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8666 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8667 | MockWrite( |
| 8668 | "PUT / HTTP/1.1\r\n" |
| 8669 | "Host: www.example.org\r\n" |
| 8670 | "Connection: keep-alive\r\n" |
| 8671 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8672 | }; |
| 8673 | |
| 8674 | // Lastly, the server responds with the actual content. |
| 8675 | MockRead data_reads[] = { |
| 8676 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8677 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8678 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8679 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8680 | }; |
| 8681 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8682 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8683 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8684 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8686 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8690 | |
| 8691 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8692 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8693 | } |
| 8694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8695 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8696 | HttpRequestInfo request; |
| 8697 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8698 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8702 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8703 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8704 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8705 | "Host: www.example.org\r\n" |
| 8706 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8707 | }; |
| 8708 | |
| 8709 | // Lastly, the server responds with the actual content. |
| 8710 | MockRead data_reads[] = { |
| 8711 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8712 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8713 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8715 | }; |
| 8716 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8717 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8718 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8721 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8725 | |
| 8726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8728 | } |
| 8729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8730 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8731 | HttpRequestInfo request; |
| 8732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8734 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8738 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8739 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8740 | MockWrite( |
| 8741 | "GET / HTTP/1.1\r\n" |
| 8742 | "Host: www.example.org\r\n" |
| 8743 | "Connection: keep-alive\r\n" |
| 8744 | "Pragma: no-cache\r\n" |
| 8745 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8746 | }; |
| 8747 | |
| 8748 | // Lastly, the server responds with the actual content. |
| 8749 | MockRead data_reads[] = { |
| 8750 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8752 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8753 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8754 | }; |
| 8755 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8756 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8757 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8760 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8762 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8764 | |
| 8765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8767 | } |
| 8768 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8769 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8770 | HttpRequestInfo request; |
| 8771 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8772 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8773 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8777 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8778 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8779 | MockWrite( |
| 8780 | "GET / HTTP/1.1\r\n" |
| 8781 | "Host: www.example.org\r\n" |
| 8782 | "Connection: keep-alive\r\n" |
| 8783 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8784 | }; |
| 8785 | |
| 8786 | // Lastly, the server responds with the actual content. |
| 8787 | MockRead data_reads[] = { |
| 8788 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8789 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8790 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8792 | }; |
| 8793 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8794 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8795 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8798 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8800 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8802 | |
| 8803 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8804 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8805 | } |
| 8806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8807 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8808 | HttpRequestInfo request; |
| 8809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8810 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8811 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8815 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8816 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8817 | MockWrite( |
| 8818 | "GET / HTTP/1.1\r\n" |
| 8819 | "Host: www.example.org\r\n" |
| 8820 | "Connection: keep-alive\r\n" |
| 8821 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8822 | }; |
| 8823 | |
| 8824 | // Lastly, the server responds with the actual content. |
| 8825 | MockRead data_reads[] = { |
| 8826 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8827 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8828 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8829 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8830 | }; |
| 8831 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8832 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8833 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8836 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8840 | |
| 8841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8843 | } |
| 8844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8845 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8846 | HttpRequestInfo request; |
| 8847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8849 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8850 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8851 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8855 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8856 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8857 | MockWrite( |
| 8858 | "GET / HTTP/1.1\r\n" |
| 8859 | "Host: www.example.org\r\n" |
| 8860 | "Connection: keep-alive\r\n" |
| 8861 | "referer: www.foo.com\r\n" |
| 8862 | "hEllo: Kitty\r\n" |
| 8863 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8864 | }; |
| 8865 | |
| 8866 | // Lastly, the server responds with the actual content. |
| 8867 | MockRead data_reads[] = { |
| 8868 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8872 | }; |
| 8873 | |
| 8874 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8875 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8876 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8878 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8880 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8882 | |
| 8883 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8885 | } |
| 8886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8887 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8888 | HttpRequestInfo request; |
| 8889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8890 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8891 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8892 | session_deps_.proxy_service = |
| 8893 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8894 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8895 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8899 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8900 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8901 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8902 | |
| 8903 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8904 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8905 | MockWrite( |
| 8906 | "GET / HTTP/1.1\r\n" |
| 8907 | "Host: www.example.org\r\n" |
| 8908 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8909 | |
| 8910 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8911 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8912 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8914 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8915 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8916 | }; |
| 8917 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8918 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8919 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8922 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8926 | |
| 8927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8930 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8931 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8932 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8933 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8934 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8935 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8936 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8937 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8938 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8939 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8940 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8941 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8942 | EXPECT_EQ("Payload", response_text); |
| 8943 | } |
| 8944 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8945 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8946 | HttpRequestInfo request; |
| 8947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8948 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8949 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8950 | session_deps_.proxy_service = |
| 8951 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8952 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8953 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8954 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8957 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8958 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8959 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8960 | |
| 8961 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8962 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8963 | arraysize(write_buffer)), |
| 8964 | MockWrite( |
| 8965 | "GET / HTTP/1.1\r\n" |
| 8966 | "Host: www.example.org\r\n" |
| 8967 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8968 | |
| 8969 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8970 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8971 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8972 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8973 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8974 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8975 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8976 | }; |
| 8977 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8978 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8979 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8981 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8982 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8985 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8986 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8987 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8989 | |
| 8990 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8991 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8992 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8993 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8994 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8995 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8996 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8998 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8999 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9000 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9001 | |
| 9002 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9003 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9005 | EXPECT_EQ("Payload", response_text); |
| 9006 | } |
| 9007 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9008 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9009 | HttpRequestInfo request; |
| 9010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9011 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9012 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9013 | session_deps_.proxy_service = |
| 9014 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9015 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9016 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9017 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9019 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9020 | |
| 9021 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9022 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9023 | |
| 9024 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9025 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9026 | MockWrite( |
| 9027 | "GET / HTTP/1.1\r\n" |
| 9028 | "Host: www.example.org\r\n" |
| 9029 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9030 | |
| 9031 | MockRead data_reads[] = { |
| 9032 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9033 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9034 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9035 | MockRead("Payload"), |
| 9036 | MockRead(SYNCHRONOUS, OK) |
| 9037 | }; |
| 9038 | |
| 9039 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9040 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9042 | |
| 9043 | TestCompletionCallback callback; |
| 9044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9047 | |
| 9048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9049 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9051 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9052 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9053 | |
| 9054 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9055 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9056 | TestLoadTimingNotReused(load_timing_info, |
| 9057 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9058 | |
| 9059 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9060 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9061 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9062 | EXPECT_EQ("Payload", response_text); |
| 9063 | } |
| 9064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9065 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9066 | HttpRequestInfo request; |
| 9067 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9069 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9070 | session_deps_.proxy_service = |
| 9071 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9072 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9073 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9074 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9077 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9078 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9079 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9080 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9081 | 0x05, // Version |
| 9082 | 0x01, // Command (CONNECT) |
| 9083 | 0x00, // Reserved. |
| 9084 | 0x03, // Address type (DOMAINNAME). |
| 9085 | 0x0F, // Length of domain (15) |
| 9086 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9087 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9088 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9089 | const char kSOCKS5OkResponse[] = |
| 9090 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9091 | |
| 9092 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9093 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9094 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9095 | MockWrite( |
| 9096 | "GET / HTTP/1.1\r\n" |
| 9097 | "Host: www.example.org\r\n" |
| 9098 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9099 | |
| 9100 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9101 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9102 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9103 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9104 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9105 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9106 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9107 | }; |
| 9108 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9109 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9110 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9113 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9115 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9117 | |
| 9118 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9122 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9123 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9124 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9125 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9126 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9127 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9128 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9129 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9130 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9131 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9133 | EXPECT_EQ("Payload", response_text); |
| 9134 | } |
| 9135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9136 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9137 | HttpRequestInfo request; |
| 9138 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9139 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9140 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9141 | session_deps_.proxy_service = |
| 9142 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9143 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9144 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9147 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9148 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9149 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9150 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9151 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9152 | 0x05, // Version |
| 9153 | 0x01, // Command (CONNECT) |
| 9154 | 0x00, // Reserved. |
| 9155 | 0x03, // Address type (DOMAINNAME). |
| 9156 | 0x0F, // Length of domain (15) |
| 9157 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9158 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9159 | }; |
| 9160 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9161 | const char kSOCKS5OkResponse[] = |
| 9162 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9163 | |
| 9164 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9165 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9166 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9167 | arraysize(kSOCKS5OkRequest)), |
| 9168 | MockWrite( |
| 9169 | "GET / HTTP/1.1\r\n" |
| 9170 | "Host: www.example.org\r\n" |
| 9171 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9172 | |
| 9173 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9174 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9175 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9176 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9177 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9178 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9179 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9180 | }; |
| 9181 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9182 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9183 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9184 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9185 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9186 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9187 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9189 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9190 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9191 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9193 | |
| 9194 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9195 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9196 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9197 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9198 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9199 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9200 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9201 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9202 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9203 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9204 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9205 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9206 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9207 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9209 | EXPECT_EQ("Payload", response_text); |
| 9210 | } |
| 9211 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9212 | namespace { |
| 9213 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9214 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9215 | |
| 9216 | struct GroupNameTest { |
| 9217 | std::string proxy_server; |
| 9218 | std::string url; |
| 9219 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9220 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9221 | }; |
| 9222 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9223 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9224 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9226 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9227 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9228 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9229 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9230 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9231 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9232 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9233 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9234 | |
| 9235 | return session; |
| 9236 | } |
| 9237 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9238 | int GroupNameTransactionHelper(const std::string& url, |
| 9239 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9240 | HttpRequestInfo request; |
| 9241 | request.method = "GET"; |
| 9242 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9246 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9247 | |
| 9248 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9249 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9250 | } |
| 9251 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9252 | } // namespace |
| 9253 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9254 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9255 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9256 | { |
| 9257 | "", // unused |
| 9258 | "http://www.example.org/direct", |
| 9259 | "www.example.org:80", |
| 9260 | false, |
| 9261 | }, |
| 9262 | { |
| 9263 | "", // unused |
| 9264 | "http://[2001:1418:13:1::25]/direct", |
| 9265 | "[2001:1418:13:1::25]:80", |
| 9266 | false, |
| 9267 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9268 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9269 | // SSL Tests |
| 9270 | { |
| 9271 | "", // unused |
| 9272 | "https://www.example.org/direct_ssl", |
| 9273 | "ssl/www.example.org:443", |
| 9274 | true, |
| 9275 | }, |
| 9276 | { |
| 9277 | "", // unused |
| 9278 | "https://[2001:1418:13:1::25]/direct", |
| 9279 | "ssl/[2001:1418:13:1::25]:443", |
| 9280 | true, |
| 9281 | }, |
| 9282 | { |
| 9283 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9284 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9285 | "ssl/host.with.alternate:443", |
| 9286 | true, |
| 9287 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9288 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9289 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9290 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9291 | session_deps_.proxy_service = |
| 9292 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9293 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9294 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9295 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9296 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9297 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9298 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9299 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9300 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9301 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9302 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9303 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9304 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9305 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9306 | |
| 9307 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9308 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9309 | if (tests[i].ssl) |
| 9310 | EXPECT_EQ(tests[i].expected_group_name, |
| 9311 | ssl_conn_pool->last_group_name_received()); |
| 9312 | else |
| 9313 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9314 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9315 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9316 | } |
| 9317 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9318 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9319 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9320 | { |
| 9321 | "http_proxy", |
| 9322 | "http://www.example.org/http_proxy_normal", |
| 9323 | "www.example.org:80", |
| 9324 | false, |
| 9325 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9326 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9327 | // SSL Tests |
| 9328 | { |
| 9329 | "http_proxy", |
| 9330 | "https://www.example.org/http_connect_ssl", |
| 9331 | "ssl/www.example.org:443", |
| 9332 | true, |
| 9333 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9335 | { |
| 9336 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9337 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9338 | "ssl/host.with.alternate:443", |
| 9339 | true, |
| 9340 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9341 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9342 | { |
| 9343 | "http_proxy", |
| 9344 | "ftp://ftp.google.com/http_proxy_normal", |
| 9345 | "ftp/ftp.google.com:21", |
| 9346 | false, |
| 9347 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9348 | }; |
| 9349 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9350 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9351 | session_deps_.proxy_service = |
| 9352 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9353 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9354 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9355 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9356 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9357 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9358 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9359 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9360 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9361 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9362 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9363 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9364 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9365 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9366 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9367 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9368 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9369 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9370 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9371 | |
| 9372 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9373 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9374 | if (tests[i].ssl) |
| 9375 | EXPECT_EQ(tests[i].expected_group_name, |
| 9376 | ssl_conn_pool->last_group_name_received()); |
| 9377 | else |
| 9378 | EXPECT_EQ(tests[i].expected_group_name, |
| 9379 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9380 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9381 | } |
| 9382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9383 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9384 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9385 | { |
| 9386 | "socks4://socks_proxy:1080", |
| 9387 | "http://www.example.org/socks4_direct", |
| 9388 | "socks4/www.example.org:80", |
| 9389 | false, |
| 9390 | }, |
| 9391 | { |
| 9392 | "socks5://socks_proxy:1080", |
| 9393 | "http://www.example.org/socks5_direct", |
| 9394 | "socks5/www.example.org:80", |
| 9395 | false, |
| 9396 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9397 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9398 | // SSL Tests |
| 9399 | { |
| 9400 | "socks4://socks_proxy:1080", |
| 9401 | "https://www.example.org/socks4_ssl", |
| 9402 | "socks4/ssl/www.example.org:443", |
| 9403 | true, |
| 9404 | }, |
| 9405 | { |
| 9406 | "socks5://socks_proxy:1080", |
| 9407 | "https://www.example.org/socks5_ssl", |
| 9408 | "socks5/ssl/www.example.org:443", |
| 9409 | true, |
| 9410 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9411 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9412 | { |
| 9413 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9414 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9415 | "socks4/ssl/host.with.alternate:443", |
| 9416 | true, |
| 9417 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9418 | }; |
| 9419 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9420 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9421 | session_deps_.proxy_service = |
| 9422 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9423 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9424 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9425 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9426 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9427 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9428 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9429 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9430 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9431 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9432 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9433 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9434 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9435 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9436 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9437 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9438 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9439 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9440 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9443 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9444 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9445 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9446 | if (tests[i].ssl) |
| 9447 | EXPECT_EQ(tests[i].expected_group_name, |
| 9448 | ssl_conn_pool->last_group_name_received()); |
| 9449 | else |
| 9450 | EXPECT_EQ(tests[i].expected_group_name, |
| 9451 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9452 | } |
| 9453 | } |
| 9454 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9455 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9456 | HttpRequestInfo request; |
| 9457 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9458 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9459 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9460 | session_deps_.proxy_service = |
| 9461 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9462 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9463 | // This simulates failure resolving all hostnames; that means we will fail |
| 9464 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9465 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9466 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9467 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9470 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9472 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9474 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9476 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9477 | } |
| 9478 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9479 | // Base test to make sure that when the load flags for a request specify to |
| 9480 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9481 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9482 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9483 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9484 | HttpRequestInfo request_info; |
| 9485 | request_info.method = "GET"; |
| 9486 | request_info.load_flags = load_flags; |
| 9487 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9488 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9489 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9490 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9491 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9493 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9494 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9495 | // 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] | 9496 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9497 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9498 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9499 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9500 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9501 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9502 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9506 | |
| 9507 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9508 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9509 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9510 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9511 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9512 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9513 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9514 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9515 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9516 | // 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] | 9517 | // we can tell if the next lookup hit the cache, or the "network". |
| 9518 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9519 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9520 | |
| 9521 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9522 | // 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] | 9523 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9524 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9525 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9526 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9527 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9528 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9529 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9530 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9531 | |
| 9532 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9533 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9534 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9535 | } |
| 9536 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9537 | // There are multiple load flags that should trigger the host cache bypass. |
| 9538 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9539 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9540 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9541 | } |
| 9542 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9543 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9544 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9545 | } |
| 9546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9547 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9548 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9549 | } |
| 9550 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9551 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9552 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9553 | HttpRequestInfo request; |
| 9554 | request.method = "GET"; |
| 9555 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9556 | |
| 9557 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9558 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9559 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9560 | StaticSocketDataProvider data(NULL, 0, |
| 9561 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9562 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9565 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9567 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9568 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9569 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9571 | |
| 9572 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9573 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9574 | |
| 9575 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9576 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9577 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9578 | } |
| 9579 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9580 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9581 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9582 | HttpRequestInfo request; |
| 9583 | request.method = "GET"; |
| 9584 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9585 | |
| 9586 | MockRead data_reads[] = { |
| 9587 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9588 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9589 | }; |
| 9590 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9591 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9595 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9597 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9598 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9599 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9601 | |
| 9602 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9603 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9604 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9605 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9606 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9607 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9608 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9609 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9610 | |
| 9611 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9612 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9613 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9614 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9615 | |
| 9616 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9617 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9618 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9619 | } |
| 9620 | |
| 9621 | // Make sure that a dropped connection while draining the body for auth |
| 9622 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9623 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9624 | HttpRequestInfo request; |
| 9625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9626 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9627 | |
| 9628 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9629 | MockWrite( |
| 9630 | "GET / HTTP/1.1\r\n" |
| 9631 | "Host: www.example.org\r\n" |
| 9632 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9633 | }; |
| 9634 | |
| 9635 | MockRead data_reads1[] = { |
| 9636 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9637 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9639 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9640 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9641 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9642 | }; |
| 9643 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9644 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9645 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9648 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9649 | // be issuing -- the final header line contains the credentials. |
| 9650 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9651 | MockWrite( |
| 9652 | "GET / HTTP/1.1\r\n" |
| 9653 | "Host: www.example.org\r\n" |
| 9654 | "Connection: keep-alive\r\n" |
| 9655 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9656 | }; |
| 9657 | |
| 9658 | // Lastly, the server responds with the actual content. |
| 9659 | MockRead data_reads2[] = { |
| 9660 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9661 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9662 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9663 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9664 | }; |
| 9665 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9666 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9667 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9668 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9671 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9675 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9677 | |
| 9678 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9679 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9681 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9682 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9683 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9685 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9687 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9689 | |
| 9690 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9691 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9693 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9694 | ASSERT_TRUE(response); |
| 9695 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9696 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9697 | } |
| 9698 | |
| 9699 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9700 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9701 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9702 | |
| 9703 | HttpRequestInfo request; |
| 9704 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9705 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9706 | |
| 9707 | MockRead proxy_reads[] = { |
| 9708 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9709 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9710 | }; |
| 9711 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9712 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9713 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9714 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9718 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9719 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9720 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9721 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9722 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9723 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9724 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9725 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9727 | |
| 9728 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9729 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9730 | } |
| 9731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9732 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9733 | HttpRequestInfo request; |
| 9734 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9735 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9739 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9740 | MockRead data_reads[] = { |
| 9741 | 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] | 9742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9743 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9744 | |
| 9745 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9748 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9749 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9750 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9752 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9753 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9755 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9756 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9757 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9758 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9759 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9760 | |
| 9761 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9762 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9763 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9764 | } |
| 9765 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9766 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9767 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9768 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9769 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9770 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9771 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9773 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9774 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9775 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9776 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9777 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9778 | |
| 9779 | HttpRequestInfo request; |
| 9780 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9781 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9782 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9786 | |
| 9787 | MockRead data_reads[] = { |
| 9788 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9789 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9791 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9792 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9795 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9799 | |
| 9800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9801 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9804 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9805 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9806 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9807 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9808 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9809 | } |
| 9810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9811 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9812 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9813 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9814 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9815 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9816 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9817 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9818 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9819 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9820 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9821 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9822 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9823 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9824 | |
| 9825 | HttpRequestInfo request; |
| 9826 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9827 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9828 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9829 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9830 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9833 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9834 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9837 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9841 | |
| 9842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9843 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9844 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9845 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9846 | } |
| 9847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9848 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9849 | class FakeUploadElementReader : public UploadElementReader { |
| 9850 | public: |
| 9851 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9852 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9853 | |
| 9854 | const CompletionCallback& callback() const { return callback_; } |
| 9855 | |
| 9856 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9857 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9858 | callback_ = callback; |
| 9859 | return ERR_IO_PENDING; |
| 9860 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9861 | uint64_t GetContentLength() const override { return 0; } |
| 9862 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9863 | int Read(IOBuffer* buf, |
| 9864 | int buf_length, |
| 9865 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9866 | return ERR_FAILED; |
| 9867 | } |
| 9868 | |
| 9869 | private: |
| 9870 | CompletionCallback callback_; |
| 9871 | }; |
| 9872 | |
| 9873 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9874 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9875 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9876 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9877 | |
| 9878 | HttpRequestInfo request; |
| 9879 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9880 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9881 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9882 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9883 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9884 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9886 | |
| 9887 | StaticSocketDataProvider data; |
| 9888 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9889 | |
| 9890 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9891 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9893 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9894 | |
| 9895 | // Transaction is pending on request body initialization. |
| 9896 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9897 | |
| 9898 | // Return Init()'s result after the transaction gets destroyed. |
| 9899 | trans.reset(); |
| 9900 | fake_reader->callback().Run(OK); // Should not crash. |
| 9901 | } |
| 9902 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9903 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9904 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9905 | HttpRequestInfo request; |
| 9906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9907 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9908 | |
| 9909 | // First transaction will request a resource and receive a Basic challenge |
| 9910 | // with realm="first_realm". |
| 9911 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9912 | MockWrite( |
| 9913 | "GET / HTTP/1.1\r\n" |
| 9914 | "Host: www.example.org\r\n" |
| 9915 | "Connection: keep-alive\r\n" |
| 9916 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9917 | }; |
| 9918 | MockRead data_reads1[] = { |
| 9919 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9920 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9921 | "\r\n"), |
| 9922 | }; |
| 9923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9924 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9925 | // for first_realm. The server will reject and provide a challenge with |
| 9926 | // second_realm. |
| 9927 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9928 | MockWrite( |
| 9929 | "GET / HTTP/1.1\r\n" |
| 9930 | "Host: www.example.org\r\n" |
| 9931 | "Connection: keep-alive\r\n" |
| 9932 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9933 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9934 | }; |
| 9935 | MockRead data_reads2[] = { |
| 9936 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9937 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9938 | "\r\n"), |
| 9939 | }; |
| 9940 | |
| 9941 | // This again fails, and goes back to first_realm. Make sure that the |
| 9942 | // entry is removed from cache. |
| 9943 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9944 | MockWrite( |
| 9945 | "GET / HTTP/1.1\r\n" |
| 9946 | "Host: www.example.org\r\n" |
| 9947 | "Connection: keep-alive\r\n" |
| 9948 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9949 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9950 | }; |
| 9951 | MockRead data_reads3[] = { |
| 9952 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9953 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9954 | "\r\n"), |
| 9955 | }; |
| 9956 | |
| 9957 | // Try one last time (with the correct password) and get the resource. |
| 9958 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9959 | MockWrite( |
| 9960 | "GET / HTTP/1.1\r\n" |
| 9961 | "Host: www.example.org\r\n" |
| 9962 | "Connection: keep-alive\r\n" |
| 9963 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9964 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9965 | }; |
| 9966 | MockRead data_reads4[] = { |
| 9967 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9968 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9969 | "Content-Length: 5\r\n" |
| 9970 | "\r\n" |
| 9971 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9972 | }; |
| 9973 | |
| 9974 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9975 | data_writes1, arraysize(data_writes1)); |
| 9976 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9977 | data_writes2, arraysize(data_writes2)); |
| 9978 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9979 | data_writes3, arraysize(data_writes3)); |
| 9980 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9981 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9982 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9983 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9984 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9987 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9988 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9989 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9990 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9991 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9992 | // Issue the first request with Authorize headers. There should be a |
| 9993 | // password prompt for first_realm waiting to be filled in after the |
| 9994 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9995 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9997 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9998 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10000 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10001 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10002 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10003 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10004 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10005 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10006 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10007 | |
| 10008 | // Issue the second request with an incorrect password. There should be a |
| 10009 | // password prompt for second_realm waiting to be filled in after the |
| 10010 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10011 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10012 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10013 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10015 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10016 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10017 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10018 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10019 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10020 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10021 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10022 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10023 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10024 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10025 | |
| 10026 | // Issue the third request with another incorrect password. There should be |
| 10027 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10028 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10029 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10030 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10031 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10032 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10034 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10035 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10036 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10037 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10038 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10039 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10040 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10041 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10042 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10043 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10044 | |
| 10045 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10046 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10047 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10048 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10050 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10051 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10052 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10053 | ASSERT_TRUE(response); |
| 10054 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10055 | } |
| 10056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10057 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10058 | MockRead data_reads[] = { |
| 10059 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10060 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10061 | MockRead("\r\n"), |
| 10062 | MockRead("hello world"), |
| 10063 | MockRead(SYNCHRONOUS, OK), |
| 10064 | }; |
| 10065 | |
| 10066 | HttpRequestInfo request; |
| 10067 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10068 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10069 | |
| 10070 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10072 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10073 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10075 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10076 | TestCompletionCallback callback; |
| 10077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10081 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10083 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10084 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10085 | HttpServerProperties* http_server_properties = |
| 10086 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10087 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10088 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10089 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10090 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10091 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10093 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10094 | ASSERT_TRUE(response); |
| 10095 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10096 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10097 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10098 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10099 | |
| 10100 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10101 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10102 | EXPECT_EQ("hello world", response_data); |
| 10103 | |
| 10104 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10105 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10106 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10107 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10108 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10109 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10110 | } |
| 10111 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10112 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10113 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10114 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10115 | MockRead data_reads[] = { |
| 10116 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10117 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10118 | MockRead("\r\n"), |
| 10119 | MockRead("hello world"), |
| 10120 | MockRead(SYNCHRONOUS, OK), |
| 10121 | }; |
| 10122 | |
| 10123 | HttpRequestInfo request; |
| 10124 | request.method = "GET"; |
| 10125 | request.url = GURL("http://www.example.org/"); |
| 10126 | request.load_flags = 0; |
| 10127 | |
| 10128 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10130 | |
| 10131 | TestCompletionCallback callback; |
| 10132 | |
| 10133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10135 | |
| 10136 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10137 | HttpServerProperties* http_server_properties = |
| 10138 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10139 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10140 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10141 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10142 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10143 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10145 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10148 | ASSERT_TRUE(response); |
| 10149 | ASSERT_TRUE(response->headers); |
| 10150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10151 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10152 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10153 | |
| 10154 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10155 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10156 | EXPECT_EQ("hello world", response_data); |
| 10157 | |
| 10158 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10159 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10160 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10161 | } |
| 10162 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10163 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 10164 | // hostname is different from that of origin. |
| 10165 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10166 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10167 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10168 | session_deps_.enable_http2_alternative_service_with_different_host = false; |
| 10169 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10170 | HttpRequestInfo request; |
| 10171 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10172 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10173 | request.load_flags = 0; |
| 10174 | |
| 10175 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10176 | StaticSocketDataProvider first_data; |
| 10177 | first_data.set_connect_data(mock_connect); |
| 10178 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10179 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10180 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10181 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10182 | |
| 10183 | MockRead data_reads[] = { |
| 10184 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10185 | MockRead(ASYNC, OK), |
| 10186 | }; |
| 10187 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10188 | 0); |
| 10189 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10190 | |
| 10191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10192 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10193 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10194 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10195 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10196 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10197 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10198 | http_server_properties->SetAlternativeService( |
| 10199 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10202 | TestCompletionCallback callback; |
| 10203 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10205 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10206 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10207 | } |
| 10208 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10209 | // Regression test for https://crbug.com/615497: |
| 10210 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10211 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10212 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10213 | HttpRequestInfo request; |
| 10214 | request.method = "GET"; |
| 10215 | request.url = GURL("http://www.example.org/"); |
| 10216 | request.load_flags = 0; |
| 10217 | |
| 10218 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10219 | StaticSocketDataProvider first_data; |
| 10220 | first_data.set_connect_data(mock_connect); |
| 10221 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10222 | |
| 10223 | MockRead data_reads[] = { |
| 10224 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10225 | MockRead(ASYNC, OK), |
| 10226 | }; |
| 10227 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10228 | 0); |
| 10229 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10230 | |
| 10231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10232 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10233 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10234 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10235 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10236 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10237 | http_server_properties->SetAlternativeService( |
| 10238 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10241 | TestCompletionCallback callback; |
| 10242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10244 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10245 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10246 | } |
| 10247 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10248 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10249 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10251 | HttpServerProperties* http_server_properties = |
| 10252 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10253 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10254 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10255 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10256 | http_server_properties->SetAlternativeService( |
| 10257 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10258 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10259 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10260 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10261 | |
| 10262 | // Send a clear header. |
| 10263 | MockRead data_reads[] = { |
| 10264 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10265 | MockRead("Alt-Svc: clear\r\n"), |
| 10266 | MockRead("\r\n"), |
| 10267 | MockRead("hello world"), |
| 10268 | MockRead(SYNCHRONOUS, OK), |
| 10269 | }; |
| 10270 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10271 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10272 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10273 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10275 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10276 | HttpRequestInfo request; |
| 10277 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10278 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10279 | |
| 10280 | TestCompletionCallback callback; |
| 10281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10282 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10285 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10287 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10288 | ASSERT_TRUE(response); |
| 10289 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10290 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10291 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10292 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10293 | |
| 10294 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10295 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10296 | EXPECT_EQ("hello world", response_data); |
| 10297 | |
| 10298 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10299 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10300 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10301 | } |
| 10302 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10303 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10304 | MockRead data_reads[] = { |
| 10305 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10306 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10307 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10308 | MockRead("hello world"), |
| 10309 | MockRead(SYNCHRONOUS, OK), |
| 10310 | }; |
| 10311 | |
| 10312 | HttpRequestInfo request; |
| 10313 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10314 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10315 | |
| 10316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10318 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10319 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10321 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10322 | TestCompletionCallback callback; |
| 10323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10326 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10329 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10330 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10331 | HttpServerProperties* http_server_properties = |
| 10332 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10333 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10334 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10335 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10336 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10337 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10339 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10340 | ASSERT_TRUE(response); |
| 10341 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10343 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10344 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10345 | |
| 10346 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10347 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10348 | EXPECT_EQ("hello world", response_data); |
| 10349 | |
| 10350 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10351 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10352 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10353 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10354 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10355 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10356 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10357 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10358 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10359 | } |
| 10360 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10361 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10362 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10363 | HostPortPair alternative("alternative.example.org", 443); |
| 10364 | std::string origin_url = "https://origin.example.org:443"; |
| 10365 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10366 | |
| 10367 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10368 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10369 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10371 | |
| 10372 | // HTTP/1.1 data for request. |
| 10373 | MockWrite http_writes[] = { |
| 10374 | MockWrite("GET / HTTP/1.1\r\n" |
| 10375 | "Host: alternative.example.org\r\n" |
| 10376 | "Connection: keep-alive\r\n\r\n"), |
| 10377 | }; |
| 10378 | |
| 10379 | MockRead http_reads[] = { |
| 10380 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10381 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10382 | "Content-Length: 40\r\n\r\n" |
| 10383 | "first HTTP/1.1 response from alternative"), |
| 10384 | }; |
| 10385 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10386 | http_writes, arraysize(http_writes)); |
| 10387 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10388 | |
| 10389 | StaticSocketDataProvider data_refused; |
| 10390 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10391 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10392 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10393 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10395 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10396 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10397 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10398 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10399 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10400 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10401 | // Mark the QUIC alternative service as broken. |
| 10402 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10403 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10404 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10406 | request.method = "GET"; |
| 10407 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10408 | TestCompletionCallback callback; |
| 10409 | NetErrorDetails details; |
| 10410 | EXPECT_FALSE(details.quic_broken); |
| 10411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10412 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10413 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10414 | EXPECT_TRUE(details.quic_broken); |
| 10415 | } |
| 10416 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10417 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10418 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10419 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10420 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10421 | std::string origin_url = "https://origin.example.org:443"; |
| 10422 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10423 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10424 | |
| 10425 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10426 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10427 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10429 | |
| 10430 | // HTTP/1.1 data for request. |
| 10431 | MockWrite http_writes[] = { |
| 10432 | MockWrite("GET / HTTP/1.1\r\n" |
| 10433 | "Host: alternative1.example.org\r\n" |
| 10434 | "Connection: keep-alive\r\n\r\n"), |
| 10435 | }; |
| 10436 | |
| 10437 | MockRead http_reads[] = { |
| 10438 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10439 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10440 | "Content-Length: 40\r\n\r\n" |
| 10441 | "first HTTP/1.1 response from alternative1"), |
| 10442 | }; |
| 10443 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10444 | http_writes, arraysize(http_writes)); |
| 10445 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10446 | |
| 10447 | StaticSocketDataProvider data_refused; |
| 10448 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10449 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10452 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10453 | session->http_server_properties(); |
| 10454 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10455 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10456 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10457 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10458 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10459 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10460 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10461 | expiration); |
| 10462 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10463 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10464 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10465 | expiration); |
| 10466 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10467 | |
| 10468 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10469 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10470 | |
| 10471 | // Mark one of the QUIC alternative service as broken. |
| 10472 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10473 | |
| 10474 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10475 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10476 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10477 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10479 | request.method = "GET"; |
| 10480 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10481 | TestCompletionCallback callback; |
| 10482 | NetErrorDetails details; |
| 10483 | EXPECT_FALSE(details.quic_broken); |
| 10484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10485 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10486 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10487 | EXPECT_FALSE(details.quic_broken); |
| 10488 | } |
| 10489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10490 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10491 | HttpRequestInfo request; |
| 10492 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10493 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10494 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10495 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10496 | StaticSocketDataProvider first_data; |
| 10497 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10498 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10499 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10500 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10502 | |
| 10503 | MockRead data_reads[] = { |
| 10504 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10505 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10506 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10507 | }; |
| 10508 | StaticSocketDataProvider second_data( |
| 10509 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10510 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10513 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10514 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10515 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10516 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10517 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10518 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10519 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10520 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10521 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10522 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10523 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10524 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10527 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10529 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10531 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10533 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10534 | ASSERT_TRUE(response); |
| 10535 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10536 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10537 | |
| 10538 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10539 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10540 | EXPECT_EQ("hello world", response_data); |
| 10541 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10542 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10543 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10544 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10545 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10546 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10547 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10548 | } |
| 10549 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10550 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10551 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10552 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10553 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10554 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10555 | HttpRequestInfo restricted_port_request; |
| 10556 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10557 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10558 | restricted_port_request.load_flags = 0; |
| 10559 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10560 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10561 | StaticSocketDataProvider first_data; |
| 10562 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10563 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10564 | |
| 10565 | MockRead data_reads[] = { |
| 10566 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10567 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10568 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10569 | }; |
| 10570 | StaticSocketDataProvider second_data( |
| 10571 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10573 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10574 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10578 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10579 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10580 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10581 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10582 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10583 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10584 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10585 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10586 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10587 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10590 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10591 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10592 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10593 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10595 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10596 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10597 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10598 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10599 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10600 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10601 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10602 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10603 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10604 | |
| 10605 | HttpRequestInfo restricted_port_request; |
| 10606 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10607 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10608 | restricted_port_request.load_flags = 0; |
| 10609 | |
| 10610 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10611 | StaticSocketDataProvider first_data; |
| 10612 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10613 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10614 | |
| 10615 | MockRead data_reads[] = { |
| 10616 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10617 | MockRead("hello world"), |
| 10618 | MockRead(ASYNC, OK), |
| 10619 | }; |
| 10620 | StaticSocketDataProvider second_data( |
| 10621 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10622 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10623 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10624 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10628 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10629 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10630 | session->http_server_properties(); |
| 10631 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10632 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10633 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10634 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10635 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10636 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10637 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10640 | TestCompletionCallback callback; |
| 10641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10642 | EXPECT_EQ(ERR_IO_PENDING, |
| 10643 | trans.Start(&restricted_port_request, callback.callback(), |
| 10644 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10645 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10646 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10647 | } |
| 10648 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10649 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10650 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10651 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10652 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10653 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10654 | HttpRequestInfo restricted_port_request; |
| 10655 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10656 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10657 | restricted_port_request.load_flags = 0; |
| 10658 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10659 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10660 | StaticSocketDataProvider first_data; |
| 10661 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10662 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10663 | |
| 10664 | MockRead data_reads[] = { |
| 10665 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10666 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10667 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10668 | }; |
| 10669 | StaticSocketDataProvider second_data( |
| 10670 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10671 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10672 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10673 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10674 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10677 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10678 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10679 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10680 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10681 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10682 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10683 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10684 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10685 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10686 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10689 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10690 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10691 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10692 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10694 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10696 | } |
| 10697 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10698 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10699 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10700 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10701 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10702 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10703 | HttpRequestInfo unrestricted_port_request; |
| 10704 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10705 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10706 | unrestricted_port_request.load_flags = 0; |
| 10707 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10708 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10709 | StaticSocketDataProvider first_data; |
| 10710 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10711 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10712 | |
| 10713 | MockRead data_reads[] = { |
| 10714 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10715 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10716 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10717 | }; |
| 10718 | StaticSocketDataProvider second_data( |
| 10719 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10720 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10721 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10722 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10726 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10727 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10728 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10729 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10730 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10731 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10732 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10733 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10734 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10735 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10738 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10740 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10741 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10743 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10744 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10745 | } |
| 10746 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10747 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10748 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10749 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10750 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10751 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10752 | HttpRequestInfo unrestricted_port_request; |
| 10753 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10754 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10755 | unrestricted_port_request.load_flags = 0; |
| 10756 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10757 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10758 | StaticSocketDataProvider first_data; |
| 10759 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10760 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10761 | |
| 10762 | MockRead data_reads[] = { |
| 10763 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10764 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10765 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10766 | }; |
| 10767 | StaticSocketDataProvider second_data( |
| 10768 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10769 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10770 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10771 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10772 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10775 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10776 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10777 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10778 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10779 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10780 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10781 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10782 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10783 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10784 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10785 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10787 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10789 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10790 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10792 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10793 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10794 | } |
| 10795 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10796 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10797 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10798 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10799 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10800 | HttpRequestInfo request; |
| 10801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10802 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10803 | |
| 10804 | // The alternate protocol request will error out before we attempt to connect, |
| 10805 | // so only the standard HTTP request will try to connect. |
| 10806 | MockRead data_reads[] = { |
| 10807 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10808 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10809 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10810 | }; |
| 10811 | StaticSocketDataProvider data( |
| 10812 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10816 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10817 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10818 | session->http_server_properties(); |
| 10819 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10820 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10821 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10822 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10823 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10824 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10826 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10827 | TestCompletionCallback callback; |
| 10828 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10829 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10831 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10834 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10835 | ASSERT_TRUE(response); |
| 10836 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10837 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10838 | |
| 10839 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10840 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10841 | EXPECT_EQ("hello world", response_data); |
| 10842 | } |
| 10843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10844 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10845 | HttpRequestInfo request; |
| 10846 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10847 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10848 | |
| 10849 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10850 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10851 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10852 | MockRead("\r\n"), |
| 10853 | MockRead("hello world"), |
| 10854 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10855 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10856 | |
| 10857 | StaticSocketDataProvider first_transaction( |
| 10858 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10860 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10861 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10863 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10864 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10865 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10866 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10867 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10868 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10869 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10870 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10871 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10872 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10873 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10874 | }; |
| 10875 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10876 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10877 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10879 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10880 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10881 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10882 | NULL, 0, NULL, 0); |
| 10883 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10884 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10885 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10886 | &hanging_non_alternate_protocol_socket); |
| 10887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10888 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10889 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10894 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10896 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10897 | |
| 10898 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10899 | ASSERT_TRUE(response); |
| 10900 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10901 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10902 | |
| 10903 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10904 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10905 | EXPECT_EQ("hello world", response_data); |
| 10906 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10907 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10908 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10909 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10911 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10912 | |
| 10913 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10914 | ASSERT_TRUE(response); |
| 10915 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10916 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10917 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10918 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10919 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10921 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10922 | } |
| 10923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10924 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10925 | HttpRequestInfo request; |
| 10926 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10927 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10928 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10929 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10931 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10932 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10933 | MockRead("\r\n"), |
| 10934 | MockRead("hello world"), |
| 10935 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10936 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10937 | }; |
| 10938 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10939 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10940 | 0); |
| 10941 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10942 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10943 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10945 | |
| 10946 | // Second transaction starts an alternative and a non-alternative Job. |
| 10947 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10948 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10949 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10950 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10951 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10952 | |
| 10953 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10954 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10955 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10956 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10957 | // Third transaction starts an alternative and a non-alternative job. |
| 10958 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10959 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10960 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10961 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10962 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10963 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10964 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10965 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10966 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10967 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10968 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10969 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10970 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10971 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10972 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10973 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10974 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10975 | }; |
| 10976 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10977 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10978 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10979 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10980 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10981 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10983 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10984 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10985 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10988 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10989 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10990 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10991 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10993 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10994 | |
| 10995 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10996 | ASSERT_TRUE(response); |
| 10997 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10998 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10999 | |
| 11000 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11001 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11002 | EXPECT_EQ("hello world", response_data); |
| 11003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11004 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11005 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11006 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11008 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11009 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11010 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11011 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11013 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11014 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11015 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11016 | |
| 11017 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11018 | ASSERT_TRUE(response); |
| 11019 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11020 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11021 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11022 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11023 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11024 | EXPECT_EQ("hello!", response_data); |
| 11025 | |
| 11026 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11027 | ASSERT_TRUE(response); |
| 11028 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11029 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11030 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11031 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11032 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11033 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11034 | } |
| 11035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11036 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11037 | HttpRequestInfo request; |
| 11038 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11039 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11040 | |
| 11041 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11042 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11043 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11044 | MockRead("\r\n"), |
| 11045 | MockRead("hello world"), |
| 11046 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11047 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11048 | }; |
| 11049 | |
| 11050 | StaticSocketDataProvider first_transaction( |
| 11051 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11052 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11053 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11054 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11056 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11057 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11058 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11059 | NULL, 0, NULL, 0); |
| 11060 | hanging_alternate_protocol_socket.set_connect_data( |
| 11061 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11062 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11063 | &hanging_alternate_protocol_socket); |
| 11064 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11065 | // 2nd request is just a copy of the first one, over HTTP/1.1 again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11066 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11067 | NULL, 0); |
| 11068 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11071 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11074 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11075 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11076 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11077 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11078 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11079 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11080 | |
| 11081 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11082 | ASSERT_TRUE(response); |
| 11083 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11084 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11085 | |
| 11086 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11087 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11088 | EXPECT_EQ("hello world", response_data); |
| 11089 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11090 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11092 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11094 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11095 | |
| 11096 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11097 | ASSERT_TRUE(response); |
| 11098 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11099 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11100 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11101 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11103 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11104 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11105 | } |
| 11106 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11107 | class CapturingProxyResolver : public ProxyResolver { |
| 11108 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11109 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11110 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11111 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11112 | int GetProxyForURL(const GURL& url, |
| 11113 | ProxyInfo* results, |
| 11114 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11115 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11116 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11117 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11118 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11119 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11120 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11121 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11122 | } |
| 11123 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11124 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11125 | |
| 11126 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11127 | std::vector<GURL> resolved_; |
| 11128 | |
| 11129 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11130 | }; |
| 11131 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11132 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11133 | public: |
| 11134 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11135 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11136 | |
| 11137 | int CreateProxyResolver( |
| 11138 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11139 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11140 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11141 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11142 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11143 | return OK; |
| 11144 | } |
| 11145 | |
| 11146 | private: |
| 11147 | ProxyResolver* resolver_; |
| 11148 | }; |
| 11149 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11150 | // Test that proxy is resolved using the origin url, |
| 11151 | // regardless of the alternative server. |
| 11152 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11153 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11154 | ProxyConfig proxy_config; |
| 11155 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11156 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11157 | auto proxy_config_service = |
| 11158 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11159 | |
| 11160 | CapturingProxyResolver capturing_proxy_resolver; |
| 11161 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11162 | &capturing_proxy_resolver); |
| 11163 | |
| 11164 | TestNetLog net_log; |
| 11165 | |
| 11166 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11167 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11168 | &net_log); |
| 11169 | |
| 11170 | session_deps_.net_log = &net_log; |
| 11171 | |
| 11172 | // Configure alternative service with a hostname that is not bypassed by the |
| 11173 | // proxy. |
| 11174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11175 | HttpServerProperties* http_server_properties = |
| 11176 | session->http_server_properties(); |
| 11177 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11178 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11179 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11180 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11181 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11182 | expiration); |
| 11183 | |
| 11184 | // Non-alternative job should hang. |
| 11185 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11186 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11187 | nullptr, 0); |
| 11188 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11189 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11190 | &hanging_alternate_protocol_socket); |
| 11191 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11192 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11193 | |
| 11194 | HttpRequestInfo request; |
| 11195 | request.method = "GET"; |
| 11196 | request.url = GURL("https://www.example.org/"); |
| 11197 | request.load_flags = 0; |
| 11198 | |
| 11199 | SpdySerializedFrame req( |
| 11200 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11201 | |
| 11202 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11203 | |
| 11204 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11205 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11206 | MockRead spdy_reads[] = { |
| 11207 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11208 | }; |
| 11209 | |
| 11210 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11211 | arraysize(spdy_writes)); |
| 11212 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11213 | |
| 11214 | TestCompletionCallback callback; |
| 11215 | |
| 11216 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11218 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11219 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11220 | |
| 11221 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11222 | ASSERT_TRUE(response); |
| 11223 | ASSERT_TRUE(response->headers); |
| 11224 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11225 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11226 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11227 | |
| 11228 | std::string response_data; |
| 11229 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11230 | EXPECT_EQ("hello!", response_data); |
| 11231 | |
| 11232 | // Origin host bypasses proxy, no resolution should have happened. |
| 11233 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11234 | } |
| 11235 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11236 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11237 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11238 | proxy_config.set_auto_detect(true); |
| 11239 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11240 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11241 | CapturingProxyResolver capturing_proxy_resolver; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11242 | session_deps_.proxy_service.reset( |
| 11243 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11244 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11245 | &capturing_proxy_resolver), |
| 11246 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11247 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11248 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11249 | |
| 11250 | HttpRequestInfo request; |
| 11251 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11252 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11253 | |
| 11254 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11255 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11256 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11257 | MockRead("\r\n"), |
| 11258 | MockRead("hello world"), |
| 11259 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11260 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11261 | }; |
| 11262 | |
| 11263 | StaticSocketDataProvider first_transaction( |
| 11264 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11265 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11266 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11267 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11269 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11270 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11271 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11272 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11273 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11274 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11275 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11276 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11277 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11278 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11279 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11280 | }; |
| 11281 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11282 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11283 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11284 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11285 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11286 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11287 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11288 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11289 | }; |
| 11290 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11291 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11292 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11293 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11294 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11295 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11296 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11297 | NULL, 0, NULL, 0); |
| 11298 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11299 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11300 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11301 | &hanging_non_alternate_protocol_socket); |
| 11302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11303 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11306 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11308 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11309 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11310 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11311 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11312 | |
| 11313 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11314 | ASSERT_TRUE(response); |
| 11315 | ASSERT_TRUE(response->headers); |
| 11316 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11317 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11318 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11319 | |
| 11320 | std::string response_data; |
| 11321 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11322 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11323 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11324 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11325 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11326 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11327 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11328 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11329 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11330 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11331 | ASSERT_TRUE(response); |
| 11332 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11333 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11334 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11335 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11336 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11337 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11338 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11339 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11340 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11341 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11342 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11343 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11344 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11345 | LoadTimingInfo load_timing_info; |
| 11346 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11347 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11348 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11349 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11350 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11351 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11352 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11353 | HttpRequestInfo request; |
| 11354 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11355 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11356 | |
| 11357 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11358 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11359 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11360 | MockRead("\r\n"), |
| 11361 | MockRead("hello world"), |
| 11362 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11363 | }; |
| 11364 | |
| 11365 | StaticSocketDataProvider first_transaction( |
| 11366 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11367 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11368 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11369 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11371 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11372 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11373 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11374 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11375 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11376 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11377 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11378 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11379 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11380 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11381 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11382 | }; |
| 11383 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11384 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11385 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11386 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11387 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11388 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11389 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11392 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11393 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11394 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11395 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11397 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11398 | |
| 11399 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11400 | ASSERT_TRUE(response); |
| 11401 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11402 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11403 | |
| 11404 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11405 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11406 | EXPECT_EQ("hello world", response_data); |
| 11407 | |
| 11408 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11409 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11410 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11411 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11412 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11413 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11414 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11415 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11416 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11417 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11419 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11420 | |
| 11421 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11422 | ASSERT_TRUE(response); |
| 11423 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11424 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11425 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11426 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11427 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11428 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11429 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11430 | } |
| 11431 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11432 | // GenerateAuthToken is a mighty big test. |
| 11433 | // It tests all permutation of GenerateAuthToken behavior: |
| 11434 | // - Synchronous and Asynchronous completion. |
| 11435 | // - OK or error on completion. |
| 11436 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11437 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11438 | // - Non-authenticating and authenticating backend. |
| 11439 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11440 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11441 | // problems generating an auth token for an authenticating proxy, we don't |
| 11442 | // need to test all permutations of the backend server). |
| 11443 | // |
| 11444 | // The test proceeds by going over each of the configuration cases, and |
| 11445 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11446 | // specifies both the configuration for the test as well as the expectations |
| 11447 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11448 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11449 | static const char kServer[] = "http://www.example.com"; |
| 11450 | static const char kSecureServer[] = "https://www.example.com"; |
| 11451 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11452 | |
| 11453 | enum AuthTiming { |
| 11454 | AUTH_NONE, |
| 11455 | AUTH_SYNC, |
| 11456 | AUTH_ASYNC, |
| 11457 | }; |
| 11458 | |
| 11459 | const MockWrite kGet( |
| 11460 | "GET / HTTP/1.1\r\n" |
| 11461 | "Host: www.example.com\r\n" |
| 11462 | "Connection: keep-alive\r\n\r\n"); |
| 11463 | const MockWrite kGetProxy( |
| 11464 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11465 | "Host: www.example.com\r\n" |
| 11466 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11467 | const MockWrite kGetAuth( |
| 11468 | "GET / HTTP/1.1\r\n" |
| 11469 | "Host: www.example.com\r\n" |
| 11470 | "Connection: keep-alive\r\n" |
| 11471 | "Authorization: auth_token\r\n\r\n"); |
| 11472 | const MockWrite kGetProxyAuth( |
| 11473 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11474 | "Host: www.example.com\r\n" |
| 11475 | "Proxy-Connection: keep-alive\r\n" |
| 11476 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11477 | const MockWrite kGetAuthThroughProxy( |
| 11478 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11479 | "Host: www.example.com\r\n" |
| 11480 | "Proxy-Connection: keep-alive\r\n" |
| 11481 | "Authorization: auth_token\r\n\r\n"); |
| 11482 | const MockWrite kGetAuthWithProxyAuth( |
| 11483 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11484 | "Host: www.example.com\r\n" |
| 11485 | "Proxy-Connection: keep-alive\r\n" |
| 11486 | "Proxy-Authorization: auth_token\r\n" |
| 11487 | "Authorization: auth_token\r\n\r\n"); |
| 11488 | const MockWrite kConnect( |
| 11489 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11490 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11491 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11492 | const MockWrite kConnectProxyAuth( |
| 11493 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11494 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11495 | "Proxy-Connection: keep-alive\r\n" |
| 11496 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11497 | |
| 11498 | const MockRead kSuccess( |
| 11499 | "HTTP/1.1 200 OK\r\n" |
| 11500 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11501 | "Content-Length: 3\r\n\r\n" |
| 11502 | "Yes"); |
| 11503 | const MockRead kFailure( |
| 11504 | "Should not be called."); |
| 11505 | const MockRead kServerChallenge( |
| 11506 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11507 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11508 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11509 | "Content-Length: 14\r\n\r\n" |
| 11510 | "Unauthorized\r\n"); |
| 11511 | const MockRead kProxyChallenge( |
| 11512 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11513 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11514 | "Proxy-Connection: close\r\n" |
| 11515 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11516 | "Content-Length: 14\r\n\r\n" |
| 11517 | "Unauthorized\r\n"); |
| 11518 | const MockRead kProxyConnected( |
| 11519 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11520 | |
| 11521 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11522 | // no constructors, but the C++ compiler on Windows warns about |
| 11523 | // unspecified data in compound literals. So, moved to using constructors, |
| 11524 | // and TestRound's created with the default constructor should not be used. |
| 11525 | struct TestRound { |
| 11526 | TestRound() |
| 11527 | : expected_rv(ERR_UNEXPECTED), |
| 11528 | extra_write(NULL), |
| 11529 | extra_read(NULL) { |
| 11530 | } |
| 11531 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11532 | int expected_rv_arg) |
| 11533 | : write(write_arg), |
| 11534 | read(read_arg), |
| 11535 | expected_rv(expected_rv_arg), |
| 11536 | extra_write(NULL), |
| 11537 | extra_read(NULL) { |
| 11538 | } |
| 11539 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11540 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11541 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11542 | : write(write_arg), |
| 11543 | read(read_arg), |
| 11544 | expected_rv(expected_rv_arg), |
| 11545 | extra_write(extra_write_arg), |
| 11546 | extra_read(extra_read_arg) { |
| 11547 | } |
| 11548 | MockWrite write; |
| 11549 | MockRead read; |
| 11550 | int expected_rv; |
| 11551 | const MockWrite* extra_write; |
| 11552 | const MockRead* extra_read; |
| 11553 | }; |
| 11554 | |
| 11555 | static const int kNoSSL = 500; |
| 11556 | |
| 11557 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11558 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11559 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11560 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11561 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11562 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11563 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11564 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11565 | int num_auth_rounds; |
| 11566 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11567 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11568 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11569 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11570 | {__LINE__, |
| 11571 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11572 | AUTH_NONE, |
| 11573 | OK, |
| 11574 | kServer, |
| 11575 | AUTH_NONE, |
| 11576 | OK, |
| 11577 | 1, |
| 11578 | kNoSSL, |
| 11579 | {TestRound(kGet, kSuccess, OK)}}, |
| 11580 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11581 | {__LINE__, |
| 11582 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11583 | AUTH_NONE, |
| 11584 | OK, |
| 11585 | kServer, |
| 11586 | AUTH_SYNC, |
| 11587 | OK, |
| 11588 | 2, |
| 11589 | kNoSSL, |
| 11590 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11591 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11592 | {__LINE__, |
| 11593 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11594 | AUTH_NONE, |
| 11595 | OK, |
| 11596 | kServer, |
| 11597 | AUTH_SYNC, |
| 11598 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11599 | 3, |
| 11600 | kNoSSL, |
| 11601 | {TestRound(kGet, kServerChallenge, OK), |
| 11602 | TestRound(kGet, kServerChallenge, OK), |
| 11603 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11604 | {__LINE__, |
| 11605 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11606 | AUTH_NONE, |
| 11607 | OK, |
| 11608 | kServer, |
| 11609 | AUTH_SYNC, |
| 11610 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11611 | 2, |
| 11612 | kNoSSL, |
| 11613 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11614 | {__LINE__, |
| 11615 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11616 | AUTH_NONE, |
| 11617 | OK, |
| 11618 | kServer, |
| 11619 | AUTH_SYNC, |
| 11620 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11621 | 2, |
| 11622 | kNoSSL, |
| 11623 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11624 | {__LINE__, |
| 11625 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11626 | AUTH_SYNC, |
| 11627 | ERR_FAILED, |
| 11628 | kServer, |
| 11629 | AUTH_NONE, |
| 11630 | OK, |
| 11631 | 2, |
| 11632 | kNoSSL, |
| 11633 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11634 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11635 | {__LINE__, |
| 11636 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11637 | AUTH_ASYNC, |
| 11638 | ERR_FAILED, |
| 11639 | kServer, |
| 11640 | AUTH_NONE, |
| 11641 | OK, |
| 11642 | 2, |
| 11643 | kNoSSL, |
| 11644 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11645 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11646 | {__LINE__, |
| 11647 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11648 | AUTH_NONE, |
| 11649 | OK, |
| 11650 | kServer, |
| 11651 | AUTH_SYNC, |
| 11652 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11653 | 2, |
| 11654 | kNoSSL, |
| 11655 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11656 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11657 | {__LINE__, |
| 11658 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11659 | AUTH_NONE, |
| 11660 | OK, |
| 11661 | kServer, |
| 11662 | AUTH_ASYNC, |
| 11663 | ERR_FAILED, |
| 11664 | 2, |
| 11665 | kNoSSL, |
| 11666 | {TestRound(kGet, kServerChallenge, OK), |
| 11667 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11668 | {__LINE__, |
| 11669 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11670 | AUTH_NONE, |
| 11671 | OK, |
| 11672 | kServer, |
| 11673 | AUTH_ASYNC, |
| 11674 | OK, |
| 11675 | 2, |
| 11676 | kNoSSL, |
| 11677 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11678 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11679 | {__LINE__, |
| 11680 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11681 | AUTH_NONE, |
| 11682 | OK, |
| 11683 | kServer, |
| 11684 | AUTH_ASYNC, |
| 11685 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11686 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11687 | kNoSSL, |
| 11688 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11689 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11690 | TestRound(kGet, kServerChallenge, OK), |
| 11691 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11692 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11693 | {__LINE__, |
| 11694 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11695 | AUTH_NONE, |
| 11696 | OK, |
| 11697 | kServer, |
| 11698 | AUTH_NONE, |
| 11699 | OK, |
| 11700 | 1, |
| 11701 | kNoSSL, |
| 11702 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11703 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11704 | {__LINE__, |
| 11705 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11706 | AUTH_NONE, |
| 11707 | OK, |
| 11708 | kServer, |
| 11709 | AUTH_SYNC, |
| 11710 | OK, |
| 11711 | 2, |
| 11712 | kNoSSL, |
| 11713 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11714 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11715 | {__LINE__, |
| 11716 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11717 | AUTH_NONE, |
| 11718 | OK, |
| 11719 | kServer, |
| 11720 | AUTH_SYNC, |
| 11721 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11722 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11723 | kNoSSL, |
| 11724 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11725 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11726 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11727 | {__LINE__, |
| 11728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11729 | AUTH_NONE, |
| 11730 | OK, |
| 11731 | kServer, |
| 11732 | AUTH_ASYNC, |
| 11733 | OK, |
| 11734 | 2, |
| 11735 | kNoSSL, |
| 11736 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11737 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11738 | {__LINE__, |
| 11739 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11740 | AUTH_NONE, |
| 11741 | OK, |
| 11742 | kServer, |
| 11743 | AUTH_ASYNC, |
| 11744 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11745 | 2, |
| 11746 | kNoSSL, |
| 11747 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11748 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11749 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11750 | {__LINE__, |
| 11751 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11752 | AUTH_SYNC, |
| 11753 | OK, |
| 11754 | kServer, |
| 11755 | AUTH_NONE, |
| 11756 | OK, |
| 11757 | 2, |
| 11758 | kNoSSL, |
| 11759 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11760 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11761 | {__LINE__, |
| 11762 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11763 | AUTH_SYNC, |
| 11764 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11765 | kServer, |
| 11766 | AUTH_NONE, |
| 11767 | OK, |
| 11768 | 2, |
| 11769 | kNoSSL, |
| 11770 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11771 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11772 | {__LINE__, |
| 11773 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11774 | AUTH_ASYNC, |
| 11775 | OK, |
| 11776 | kServer, |
| 11777 | AUTH_NONE, |
| 11778 | OK, |
| 11779 | 2, |
| 11780 | kNoSSL, |
| 11781 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11782 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11783 | {__LINE__, |
| 11784 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11785 | AUTH_ASYNC, |
| 11786 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11787 | kServer, |
| 11788 | AUTH_NONE, |
| 11789 | OK, |
| 11790 | 2, |
| 11791 | kNoSSL, |
| 11792 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11793 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11794 | {__LINE__, |
| 11795 | kProxy, |
| 11796 | AUTH_ASYNC, |
| 11797 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11798 | kServer, |
| 11799 | AUTH_NONE, |
| 11800 | OK, |
| 11801 | 3, |
| 11802 | kNoSSL, |
| 11803 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11804 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11805 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11806 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11807 | {__LINE__, |
| 11808 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11809 | AUTH_SYNC, |
| 11810 | OK, |
| 11811 | kServer, |
| 11812 | AUTH_SYNC, |
| 11813 | OK, |
| 11814 | 3, |
| 11815 | kNoSSL, |
| 11816 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11817 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11818 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11819 | {__LINE__, |
| 11820 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11821 | AUTH_SYNC, |
| 11822 | OK, |
| 11823 | kServer, |
| 11824 | AUTH_SYNC, |
| 11825 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11826 | 3, |
| 11827 | kNoSSL, |
| 11828 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11829 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11830 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11831 | {__LINE__, |
| 11832 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11833 | AUTH_ASYNC, |
| 11834 | OK, |
| 11835 | kServer, |
| 11836 | AUTH_SYNC, |
| 11837 | OK, |
| 11838 | 3, |
| 11839 | kNoSSL, |
| 11840 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11841 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11842 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11843 | {__LINE__, |
| 11844 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11845 | AUTH_ASYNC, |
| 11846 | OK, |
| 11847 | kServer, |
| 11848 | AUTH_SYNC, |
| 11849 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11850 | 3, |
| 11851 | kNoSSL, |
| 11852 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11853 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11854 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11855 | {__LINE__, |
| 11856 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11857 | AUTH_SYNC, |
| 11858 | OK, |
| 11859 | kServer, |
| 11860 | AUTH_ASYNC, |
| 11861 | OK, |
| 11862 | 3, |
| 11863 | kNoSSL, |
| 11864 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11865 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11866 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11867 | {__LINE__, |
| 11868 | kProxy, |
| 11869 | AUTH_SYNC, |
| 11870 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11871 | kServer, |
| 11872 | AUTH_ASYNC, |
| 11873 | OK, |
| 11874 | 4, |
| 11875 | kNoSSL, |
| 11876 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11877 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11878 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11879 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11880 | {__LINE__, |
| 11881 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11882 | AUTH_SYNC, |
| 11883 | OK, |
| 11884 | kServer, |
| 11885 | AUTH_ASYNC, |
| 11886 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11887 | 3, |
| 11888 | kNoSSL, |
| 11889 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11890 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11891 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11892 | {__LINE__, |
| 11893 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11894 | AUTH_ASYNC, |
| 11895 | OK, |
| 11896 | kServer, |
| 11897 | AUTH_ASYNC, |
| 11898 | OK, |
| 11899 | 3, |
| 11900 | kNoSSL, |
| 11901 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11902 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11903 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11904 | {__LINE__, |
| 11905 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11906 | AUTH_ASYNC, |
| 11907 | OK, |
| 11908 | kServer, |
| 11909 | AUTH_ASYNC, |
| 11910 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11911 | 3, |
| 11912 | kNoSSL, |
| 11913 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11914 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11915 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11916 | {__LINE__, |
| 11917 | kProxy, |
| 11918 | AUTH_ASYNC, |
| 11919 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11920 | kServer, |
| 11921 | AUTH_ASYNC, |
| 11922 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11923 | 4, |
| 11924 | kNoSSL, |
| 11925 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11926 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11927 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11928 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11929 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11930 | {__LINE__, |
| 11931 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11932 | AUTH_NONE, |
| 11933 | OK, |
| 11934 | kSecureServer, |
| 11935 | AUTH_NONE, |
| 11936 | OK, |
| 11937 | 1, |
| 11938 | 0, |
| 11939 | {TestRound(kGet, kSuccess, OK)}}, |
| 11940 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11941 | {__LINE__, |
| 11942 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11943 | AUTH_NONE, |
| 11944 | OK, |
| 11945 | kSecureServer, |
| 11946 | AUTH_SYNC, |
| 11947 | OK, |
| 11948 | 2, |
| 11949 | 0, |
| 11950 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11951 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11952 | {__LINE__, |
| 11953 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11954 | AUTH_NONE, |
| 11955 | OK, |
| 11956 | kSecureServer, |
| 11957 | AUTH_SYNC, |
| 11958 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11959 | 2, |
| 11960 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11961 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11962 | {__LINE__, |
| 11963 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11964 | AUTH_NONE, |
| 11965 | OK, |
| 11966 | kSecureServer, |
| 11967 | AUTH_ASYNC, |
| 11968 | OK, |
| 11969 | 2, |
| 11970 | 0, |
| 11971 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11972 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11973 | {__LINE__, |
| 11974 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11975 | AUTH_NONE, |
| 11976 | OK, |
| 11977 | kSecureServer, |
| 11978 | AUTH_ASYNC, |
| 11979 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11980 | 2, |
| 11981 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11982 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11983 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11984 | {__LINE__, |
| 11985 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11986 | AUTH_NONE, |
| 11987 | OK, |
| 11988 | kSecureServer, |
| 11989 | AUTH_NONE, |
| 11990 | OK, |
| 11991 | 1, |
| 11992 | 0, |
| 11993 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11994 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11995 | {__LINE__, |
| 11996 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11997 | AUTH_NONE, |
| 11998 | OK, |
| 11999 | kSecureServer, |
| 12000 | AUTH_SYNC, |
| 12001 | OK, |
| 12002 | 2, |
| 12003 | 0, |
| 12004 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12005 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12006 | {__LINE__, |
| 12007 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12008 | AUTH_NONE, |
| 12009 | OK, |
| 12010 | kSecureServer, |
| 12011 | AUTH_SYNC, |
| 12012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12013 | 2, |
| 12014 | 0, |
| 12015 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12016 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12017 | {__LINE__, |
| 12018 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12019 | AUTH_NONE, |
| 12020 | OK, |
| 12021 | kSecureServer, |
| 12022 | AUTH_ASYNC, |
| 12023 | OK, |
| 12024 | 2, |
| 12025 | 0, |
| 12026 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12027 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12028 | {__LINE__, |
| 12029 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12030 | AUTH_NONE, |
| 12031 | OK, |
| 12032 | kSecureServer, |
| 12033 | AUTH_ASYNC, |
| 12034 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12035 | 2, |
| 12036 | 0, |
| 12037 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12038 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12039 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12040 | {__LINE__, |
| 12041 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12042 | AUTH_SYNC, |
| 12043 | OK, |
| 12044 | kSecureServer, |
| 12045 | AUTH_NONE, |
| 12046 | OK, |
| 12047 | 2, |
| 12048 | 1, |
| 12049 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12050 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12051 | {__LINE__, |
| 12052 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12053 | AUTH_SYNC, |
| 12054 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12055 | kSecureServer, |
| 12056 | AUTH_NONE, |
| 12057 | OK, |
| 12058 | 2, |
| 12059 | kNoSSL, |
| 12060 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12061 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12062 | {__LINE__, |
| 12063 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12064 | AUTH_SYNC, |
| 12065 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12066 | kSecureServer, |
| 12067 | AUTH_NONE, |
| 12068 | OK, |
| 12069 | 2, |
| 12070 | kNoSSL, |
| 12071 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12072 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12073 | {__LINE__, |
| 12074 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12075 | AUTH_SYNC, |
| 12076 | ERR_UNEXPECTED, |
| 12077 | kSecureServer, |
| 12078 | AUTH_NONE, |
| 12079 | OK, |
| 12080 | 2, |
| 12081 | kNoSSL, |
| 12082 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12083 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12084 | {__LINE__, |
| 12085 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12086 | AUTH_ASYNC, |
| 12087 | OK, |
| 12088 | kSecureServer, |
| 12089 | AUTH_NONE, |
| 12090 | OK, |
| 12091 | 2, |
| 12092 | 1, |
| 12093 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12094 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12095 | {__LINE__, |
| 12096 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12097 | AUTH_ASYNC, |
| 12098 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12099 | kSecureServer, |
| 12100 | AUTH_NONE, |
| 12101 | OK, |
| 12102 | 2, |
| 12103 | kNoSSL, |
| 12104 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12105 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12106 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12107 | {__LINE__, |
| 12108 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12109 | AUTH_SYNC, |
| 12110 | OK, |
| 12111 | kSecureServer, |
| 12112 | AUTH_SYNC, |
| 12113 | OK, |
| 12114 | 3, |
| 12115 | 1, |
| 12116 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12117 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12118 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12119 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12120 | {__LINE__, |
| 12121 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12122 | AUTH_SYNC, |
| 12123 | OK, |
| 12124 | kSecureServer, |
| 12125 | AUTH_SYNC, |
| 12126 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12127 | 3, |
| 12128 | 1, |
| 12129 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12130 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12131 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12132 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12133 | {__LINE__, |
| 12134 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12135 | AUTH_ASYNC, |
| 12136 | OK, |
| 12137 | kSecureServer, |
| 12138 | AUTH_SYNC, |
| 12139 | OK, |
| 12140 | 3, |
| 12141 | 1, |
| 12142 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12143 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12144 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12145 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12146 | {__LINE__, |
| 12147 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12148 | AUTH_ASYNC, |
| 12149 | OK, |
| 12150 | kSecureServer, |
| 12151 | AUTH_SYNC, |
| 12152 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12153 | 3, |
| 12154 | 1, |
| 12155 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12156 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12157 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12158 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12159 | {__LINE__, |
| 12160 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12161 | AUTH_SYNC, |
| 12162 | OK, |
| 12163 | kSecureServer, |
| 12164 | AUTH_ASYNC, |
| 12165 | OK, |
| 12166 | 3, |
| 12167 | 1, |
| 12168 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12169 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12170 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12171 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12172 | {__LINE__, |
| 12173 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12174 | AUTH_SYNC, |
| 12175 | OK, |
| 12176 | kSecureServer, |
| 12177 | AUTH_ASYNC, |
| 12178 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12179 | 3, |
| 12180 | 1, |
| 12181 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12182 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12183 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12184 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12185 | {__LINE__, |
| 12186 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12187 | AUTH_ASYNC, |
| 12188 | OK, |
| 12189 | kSecureServer, |
| 12190 | AUTH_ASYNC, |
| 12191 | OK, |
| 12192 | 3, |
| 12193 | 1, |
| 12194 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12195 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12196 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12197 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12198 | {__LINE__, |
| 12199 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12200 | AUTH_ASYNC, |
| 12201 | OK, |
| 12202 | kSecureServer, |
| 12203 | AUTH_ASYNC, |
| 12204 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12205 | 3, |
| 12206 | 1, |
| 12207 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12208 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12209 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12210 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12211 | {__LINE__, |
| 12212 | kProxy, |
| 12213 | AUTH_ASYNC, |
| 12214 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12215 | kSecureServer, |
| 12216 | AUTH_ASYNC, |
| 12217 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12218 | 4, |
| 12219 | 2, |
| 12220 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12221 | TestRound(kConnect, kProxyChallenge, OK), |
| 12222 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12223 | &kServerChallenge), |
| 12224 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12225 | }; |
| 12226 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12227 | for (const auto& test_config : test_configs) { |
| 12228 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12229 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12230 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12231 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12232 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12233 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12234 | |
| 12235 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12236 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12237 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12238 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12239 | std::string auth_challenge = "Mock realm=proxy"; |
| 12240 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12241 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12242 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12243 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12244 | empty_ssl_info, origin, |
| 12245 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12246 | auth_handler->SetGenerateExpectation( |
| 12247 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12248 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12249 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12250 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12251 | } |
| 12252 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12253 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12254 | std::string auth_challenge = "Mock realm=server"; |
| 12255 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12256 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12257 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12258 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12259 | empty_ssl_info, origin, |
| 12260 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12261 | auth_handler->SetGenerateExpectation( |
| 12262 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12263 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12264 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12265 | |
| 12266 | // The second handler always succeeds. It should only be used where there |
| 12267 | // are multiple auth sessions for server auth in the same network |
| 12268 | // transaction using the same auth scheme. |
| 12269 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12270 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12271 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12272 | empty_ssl_info, origin, |
| 12273 | NetLogWithSource()); |
| 12274 | second_handler->SetGenerateExpectation(true, OK); |
| 12275 | auth_factory->AddMockHandler(second_handler.release(), |
| 12276 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12277 | } |
| 12278 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12279 | session_deps_.proxy_service = |
| 12280 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12281 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12282 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12283 | } |
| 12284 | |
| 12285 | HttpRequestInfo request; |
| 12286 | request.method = "GET"; |
| 12287 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12288 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12289 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12290 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12291 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12292 | |
| 12293 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12294 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12295 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12296 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12297 | |
| 12298 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12299 | mock_reads.back().push_back(read_write_round.read); |
| 12300 | mock_writes.back().push_back(read_write_round.write); |
| 12301 | |
| 12302 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12303 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12304 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12305 | mock_reads.push_back(std::vector<MockRead>()); |
| 12306 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12307 | } |
| 12308 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12309 | if (read_write_round.extra_read) { |
| 12310 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12311 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12312 | if (read_write_round.extra_write) { |
| 12313 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12314 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12315 | |
| 12316 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12317 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12318 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12319 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12320 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12322 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12323 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12324 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12325 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12326 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12327 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12328 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12329 | } |
| 12330 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12331 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12332 | // they are as well. |
| 12333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12334 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12335 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12336 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12337 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12338 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12339 | int rv; |
| 12340 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12341 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12342 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12343 | rv = trans.RestartWithAuth( |
| 12344 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12345 | } |
| 12346 | if (rv == ERR_IO_PENDING) |
| 12347 | rv = callback.WaitForResult(); |
| 12348 | |
| 12349 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12350 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12351 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12352 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12353 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12354 | continue; |
| 12355 | } |
| 12356 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12357 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12358 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12359 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12360 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12361 | } |
| 12362 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12363 | } |
| 12364 | } |
| 12365 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12366 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12367 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12368 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12369 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12370 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12371 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12372 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12373 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12374 | |
| 12375 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12376 | auth_handler->set_connection_based(true); |
| 12377 | std::string auth_challenge = "Mock realm=server"; |
| 12378 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12379 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12380 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12381 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12382 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12383 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12384 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12385 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12386 | int rv = OK; |
| 12387 | const HttpResponseInfo* response = NULL; |
| 12388 | HttpRequestInfo request; |
| 12389 | request.method = "GET"; |
| 12390 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12393 | |
| 12394 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12395 | // to validate that the TCP socket is not released to the pool between |
| 12396 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12397 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12398 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12399 | 50, // Max sockets for pool |
| 12400 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12401 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12402 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12403 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12404 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12405 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12406 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12409 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12410 | |
| 12411 | const MockWrite kGet( |
| 12412 | "GET / HTTP/1.1\r\n" |
| 12413 | "Host: www.example.com\r\n" |
| 12414 | "Connection: keep-alive\r\n\r\n"); |
| 12415 | const MockWrite kGetAuth( |
| 12416 | "GET / HTTP/1.1\r\n" |
| 12417 | "Host: www.example.com\r\n" |
| 12418 | "Connection: keep-alive\r\n" |
| 12419 | "Authorization: auth_token\r\n\r\n"); |
| 12420 | |
| 12421 | const MockRead kServerChallenge( |
| 12422 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12423 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12424 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12425 | "Content-Length: 14\r\n\r\n" |
| 12426 | "Unauthorized\r\n"); |
| 12427 | const MockRead kSuccess( |
| 12428 | "HTTP/1.1 200 OK\r\n" |
| 12429 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12430 | "Content-Length: 3\r\n\r\n" |
| 12431 | "Yes"); |
| 12432 | |
| 12433 | MockWrite writes[] = { |
| 12434 | // First round |
| 12435 | kGet, |
| 12436 | // Second round |
| 12437 | kGetAuth, |
| 12438 | // Third round |
| 12439 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12440 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12441 | kGetAuth, |
| 12442 | // Competing request |
| 12443 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12444 | }; |
| 12445 | MockRead reads[] = { |
| 12446 | // First round |
| 12447 | kServerChallenge, |
| 12448 | // Second round |
| 12449 | kServerChallenge, |
| 12450 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12451 | kServerChallenge, |
| 12452 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12453 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12454 | // Competing response |
| 12455 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12456 | }; |
| 12457 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12458 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12459 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12460 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12461 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12462 | |
| 12463 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12464 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12465 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12466 | if (rv == ERR_IO_PENDING) |
| 12467 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12468 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12469 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12470 | ASSERT_TRUE(response); |
| 12471 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12472 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12473 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12474 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12475 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12476 | // In between rounds, another request comes in for the same domain. |
| 12477 | // It should not be able to grab the TCP socket that trans has already |
| 12478 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12479 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12480 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12481 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12482 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12484 | // callback_compete.WaitForResult at this point would stall forever, |
| 12485 | // since the HttpNetworkTransaction does not release the request back to |
| 12486 | // the pool until after authentication completes. |
| 12487 | |
| 12488 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12489 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12490 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12491 | if (rv == ERR_IO_PENDING) |
| 12492 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12493 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12494 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12495 | ASSERT_TRUE(response); |
| 12496 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12497 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12498 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12499 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12500 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12501 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12502 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12503 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12504 | if (rv == ERR_IO_PENDING) |
| 12505 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12506 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12507 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12508 | ASSERT_TRUE(response); |
| 12509 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12510 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12511 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12512 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12513 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12514 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12515 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12516 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12517 | if (rv == ERR_IO_PENDING) |
| 12518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12519 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12520 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12521 | ASSERT_TRUE(response); |
| 12522 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12523 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12524 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12525 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12526 | // auth handler should transition to a DONE state in concert with the remote |
| 12527 | // server. But that's not something we can test here with a mock handler. |
| 12528 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12529 | auth_handler->state()); |
| 12530 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12531 | // Read the body since the fourth round was successful. This will also |
| 12532 | // release the socket back to the pool. |
| 12533 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12534 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12535 | if (rv == ERR_IO_PENDING) |
| 12536 | rv = callback.WaitForResult(); |
| 12537 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12538 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12539 | EXPECT_EQ(0, rv); |
| 12540 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12541 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12542 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12543 | |
| 12544 | // The competing request can now finish. Wait for the headers and then |
| 12545 | // read the body. |
| 12546 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12547 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12548 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12549 | if (rv == ERR_IO_PENDING) |
| 12550 | rv = callback.WaitForResult(); |
| 12551 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12552 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12553 | EXPECT_EQ(0, rv); |
| 12554 | |
| 12555 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12556 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12557 | } |
| 12558 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12559 | // This tests the case that a request is issued via http instead of spdy after |
| 12560 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12561 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12562 | HttpRequestInfo request; |
| 12563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12564 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12565 | |
| 12566 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12567 | MockWrite( |
| 12568 | "GET / HTTP/1.1\r\n" |
| 12569 | "Host: www.example.org\r\n" |
| 12570 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12571 | }; |
| 12572 | |
| 12573 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12574 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12575 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12576 | MockRead("\r\n"), |
| 12577 | MockRead("hello world"), |
| 12578 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12579 | }; |
| 12580 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12581 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12582 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12583 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12585 | |
| 12586 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12587 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12588 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12590 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12593 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12595 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12596 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12598 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12600 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12601 | ASSERT_TRUE(response); |
| 12602 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12603 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12604 | |
| 12605 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12606 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12607 | EXPECT_EQ("hello world", response_data); |
| 12608 | |
| 12609 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12610 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12611 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12612 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12613 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12614 | // immediate server closing of the socket. |
| 12615 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12616 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12617 | HttpRequestInfo request; |
| 12618 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12619 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12620 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12621 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12622 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12624 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12625 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12626 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12627 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12628 | |
| 12629 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12630 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12631 | }; |
| 12632 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12633 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12634 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12635 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12637 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12638 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12642 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12644 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12645 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12646 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12647 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12648 | // it gets it. This is needed since the auth handler may get destroyed |
| 12649 | // before we get a chance to query it. |
| 12650 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12651 | public: |
| 12652 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12653 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12654 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12655 | |
| 12656 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12657 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12658 | const HttpRequestInfo* request, |
| 12659 | const CompletionCallback& callback, |
| 12660 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12661 | *url_ = request->url; |
| 12662 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12663 | credentials, request, callback, auth_token); |
| 12664 | } |
| 12665 | |
| 12666 | private: |
| 12667 | GURL* url_; |
| 12668 | }; |
| 12669 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12670 | // Test that if we cancel the transaction as the connection is completing, that |
| 12671 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12672 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12673 | // Setup everything about the connection to complete synchronously, so that |
| 12674 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12675 | // for is the callback from the HttpStreamRequest. |
| 12676 | // Then cancel the transaction. |
| 12677 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12678 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12679 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12680 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12681 | MockRead(SYNCHRONOUS, "hello world"), |
| 12682 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12683 | }; |
| 12684 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12685 | HttpRequestInfo request; |
| 12686 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12687 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12688 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12691 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12692 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12693 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12694 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12695 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12696 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12697 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12698 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12699 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12700 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12701 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12703 | trans.reset(); // Cancel the transaction here. |
| 12704 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12705 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12706 | } |
| 12707 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12708 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12709 | // stream is drained properly and added back to the socket pool. The main |
| 12710 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12711 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12712 | // deleted. |
| 12713 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12714 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12715 | MockRead data_reads[] = { |
| 12716 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12717 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12718 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12719 | MockRead(ASYNC, "1"), |
| 12720 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12721 | // HttpNetworkTransaction has been deleted. |
| 12722 | MockRead(ASYNC, "2"), |
| 12723 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12724 | }; |
| 12725 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12726 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12729 | |
| 12730 | { |
| 12731 | HttpRequestInfo request; |
| 12732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12733 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12734 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12736 | TestCompletionCallback callback; |
| 12737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12740 | callback.WaitForResult(); |
| 12741 | |
| 12742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12743 | ASSERT_TRUE(response); |
| 12744 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12745 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12746 | |
| 12747 | // The transaction and HttpRequestInfo are deleted. |
| 12748 | } |
| 12749 | |
| 12750 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12751 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12752 | |
| 12753 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12754 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12755 | } |
| 12756 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12757 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12758 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12759 | session_deps_.proxy_service = |
| 12760 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12764 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12765 | HttpRequestInfo request; |
| 12766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12767 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12768 | |
| 12769 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12770 | MockWrite( |
| 12771 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12772 | "Host: www.example.org\r\n" |
| 12773 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12774 | }; |
| 12775 | |
| 12776 | MockRead data_reads1[] = { |
| 12777 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12778 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12779 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12780 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12781 | }; |
| 12782 | |
| 12783 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12784 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12785 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12787 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12789 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12790 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12791 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12792 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12793 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12795 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12797 | |
| 12798 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12801 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12802 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12803 | |
| 12804 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12805 | EXPECT_EQ(200, response->headers->response_code()); |
| 12806 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12807 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12808 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12809 | HostPortPair::FromString("myproxy:70")), |
| 12810 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12811 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12812 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12813 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12814 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12815 | |
| 12816 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12817 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12818 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12819 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12820 | } |
| 12821 | |
| 12822 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12823 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12824 | session_deps_.proxy_service = |
| 12825 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12826 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12827 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12829 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12830 | HttpRequestInfo request; |
| 12831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12832 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12833 | |
| 12834 | // Since we have proxy, should try to establish tunnel. |
| 12835 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12836 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12837 | "Host: www.example.org:443\r\n" |
| 12838 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12839 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12840 | MockWrite("GET / HTTP/1.1\r\n" |
| 12841 | "Host: www.example.org\r\n" |
| 12842 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12843 | }; |
| 12844 | |
| 12845 | MockRead data_reads1[] = { |
| 12846 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12847 | |
| 12848 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12849 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12850 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12851 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12852 | }; |
| 12853 | |
| 12854 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12855 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12856 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12857 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12858 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12860 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12863 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12864 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12865 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12866 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12868 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12870 | |
| 12871 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12872 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12873 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12874 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12875 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12876 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12877 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12878 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12879 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12880 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12881 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12883 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12884 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12885 | |
| 12886 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12887 | EXPECT_EQ(200, response->headers->response_code()); |
| 12888 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12889 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12890 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12891 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12892 | HostPortPair::FromString("myproxy:70")), |
| 12893 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12894 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12895 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12896 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12897 | |
| 12898 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12899 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12900 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12901 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12902 | } |
| 12903 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12904 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12905 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12906 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12907 | session_deps_.proxy_service = |
| 12908 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12909 | BoundTestNetLog log; |
| 12910 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12912 | |
| 12913 | HttpRequestInfo request; |
| 12914 | request.method = "GET"; |
| 12915 | request.url = GURL("https://[::1]:443/"); |
| 12916 | |
| 12917 | // Since we have proxy, should try to establish tunnel. |
| 12918 | MockWrite data_writes1[] = { |
| 12919 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12920 | "Host: [::1]:443\r\n" |
| 12921 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12922 | |
| 12923 | MockWrite("GET / HTTP/1.1\r\n" |
| 12924 | "Host: [::1]\r\n" |
| 12925 | "Connection: keep-alive\r\n\r\n"), |
| 12926 | }; |
| 12927 | |
| 12928 | MockRead data_reads1[] = { |
| 12929 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12930 | |
| 12931 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12932 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12933 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12934 | MockRead(SYNCHRONOUS, OK), |
| 12935 | }; |
| 12936 | |
| 12937 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12938 | data_writes1, arraysize(data_writes1)); |
| 12939 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12940 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12942 | |
| 12943 | TestCompletionCallback callback1; |
| 12944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12947 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12949 | |
| 12950 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12951 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12952 | TestNetLogEntry::List entries; |
| 12953 | log.GetEntries(&entries); |
| 12954 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12955 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12956 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12957 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12958 | entries, pos, |
| 12959 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12960 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12963 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12964 | |
| 12965 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12966 | EXPECT_EQ(200, response->headers->response_code()); |
| 12967 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12968 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12969 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12970 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12971 | HostPortPair::FromString("myproxy:70")), |
| 12972 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12973 | |
| 12974 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12975 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12976 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12977 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12978 | } |
| 12979 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12980 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12981 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12982 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12983 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12984 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12985 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12987 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12988 | HttpRequestInfo request; |
| 12989 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12990 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12991 | |
| 12992 | // Since we have proxy, should try to establish tunnel. |
| 12993 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12994 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12995 | "Host: www.example.org:443\r\n" |
| 12996 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12997 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12998 | MockWrite("GET / HTTP/1.1\r\n" |
| 12999 | "Host: www.example.org\r\n" |
| 13000 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13001 | }; |
| 13002 | |
| 13003 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13004 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13005 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13006 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13007 | }; |
| 13008 | |
| 13009 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13010 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13011 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13012 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13013 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13015 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13017 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13019 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13021 | |
| 13022 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13023 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13024 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13025 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13026 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13027 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13028 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13029 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13030 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13031 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13032 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13033 | } |
| 13034 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13035 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13036 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13037 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13038 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13039 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13040 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13041 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13042 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13043 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13044 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13045 | }; |
| 13046 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13047 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13048 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13049 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13050 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13051 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13052 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13056 | |
| 13057 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13058 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13059 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13060 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13061 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13062 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13063 | |
| 13064 | HttpRequestInfo request; |
| 13065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13066 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13067 | |
| 13068 | // This is the important line that marks this as a preconnect. |
| 13069 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13072 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13073 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13074 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13076 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13077 | } |
| 13078 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13079 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13080 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13081 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13082 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13083 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13084 | request_info.url = GURL("https://www.example.com/"); |
| 13085 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13086 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13087 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13088 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13089 | MockWrite data_writes[] = { |
| 13090 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13091 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13092 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13093 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13095 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13096 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13097 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13099 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13100 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13101 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13102 | rv = callback.WaitForResult(); |
| 13103 | ASSERT_EQ(error, rv); |
| 13104 | } |
| 13105 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13106 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13107 | // Just check a grab bag of cert errors. |
| 13108 | static const int kErrors[] = { |
| 13109 | ERR_CERT_COMMON_NAME_INVALID, |
| 13110 | ERR_CERT_AUTHORITY_INVALID, |
| 13111 | ERR_CERT_DATE_INVALID, |
| 13112 | }; |
| 13113 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13114 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13115 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13116 | } |
| 13117 | } |
| 13118 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13119 | // Ensure that a client certificate is removed from the SSL client auth |
| 13120 | // cache when: |
| 13121 | // 1) No proxy is involved. |
| 13122 | // 2) TLS False Start is disabled. |
| 13123 | // 3) The initial TLS handshake requests a client certificate. |
| 13124 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13125 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13126 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13127 | request_info.url = GURL("https://www.example.com/"); |
| 13128 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13129 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13130 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13131 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13132 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13133 | |
| 13134 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13135 | // CertificateRequest is received for the first time, the handshake will |
| 13136 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13137 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13138 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13139 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13140 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13141 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13142 | |
| 13143 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13144 | // False Start is not being used, the result of the SSL handshake will be |
| 13145 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13146 | // matches the result of a server sending a handshake_failure alert, |
| 13147 | // rather than a Finished message, because it requires a client |
| 13148 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13149 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13150 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13152 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13153 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13154 | |
| 13155 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13156 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13157 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13158 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13159 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13160 | // requiring a client certificate, this fallback handshake should also |
| 13161 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13162 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13163 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13165 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13166 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13167 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13168 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13169 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13170 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13171 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13172 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13173 | // requiring a client certificate, this fallback handshake should also |
| 13174 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13175 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13176 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13178 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13179 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13180 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13183 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13184 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13185 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13186 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13187 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13188 | |
| 13189 | // Complete the SSL handshake, which should abort due to requiring a |
| 13190 | // client certificate. |
| 13191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13192 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13193 | |
| 13194 | // Indicate that no certificate should be supplied. From the perspective |
| 13195 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13196 | // certificate, so this is the same as supply a |
| 13197 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13198 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13199 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13200 | |
| 13201 | // Ensure the certificate was added to the client auth cache before |
| 13202 | // allowing the connection to continue restarting. |
| 13203 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13204 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13205 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13206 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13207 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13208 | |
| 13209 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13210 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13211 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13212 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13213 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13214 | |
| 13215 | // Ensure that the client certificate is removed from the cache on a |
| 13216 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13217 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13218 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13219 | } |
| 13220 | |
| 13221 | // Ensure that a client certificate is removed from the SSL client auth |
| 13222 | // cache when: |
| 13223 | // 1) No proxy is involved. |
| 13224 | // 2) TLS False Start is enabled. |
| 13225 | // 3) The initial TLS handshake requests a client certificate. |
| 13226 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13227 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13228 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13229 | request_info.url = GURL("https://www.example.com/"); |
| 13230 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13231 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13232 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13233 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13234 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13235 | |
| 13236 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13237 | // return successfully after reading up to the peer's Certificate message. |
| 13238 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13239 | // enqueue application data to be sent in the same packet as the |
| 13240 | // ChangeCipherSpec and Finished messages. |
| 13241 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13242 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13243 | // Finished messages. If there was an error negotiating with the peer, |
| 13244 | // such as due to the peer requiring a client certificate when none was |
| 13245 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13246 | // called. |
| 13247 | |
| 13248 | // Like the non-False Start case, when a client certificate is requested by |
| 13249 | // the peer, the handshake is aborted during the Connect() call. |
| 13250 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13251 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13252 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13254 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13255 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13256 | |
| 13257 | // When a client certificate is supplied, Connect() will not be aborted |
| 13258 | // when the peer requests the certificate. Instead, the handshake will |
| 13259 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13260 | // the socket. The handshake messages are not processed until Read() is |
| 13261 | // called, which then detects that the handshake was aborted, due to the |
| 13262 | // peer sending a handshake_failure because it requires a client |
| 13263 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13264 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13265 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13267 | MockRead data2_reads[] = { |
| 13268 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13269 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13270 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13271 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13272 | |
| 13273 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13274 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13275 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13276 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13277 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13279 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13280 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13281 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13282 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13283 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13284 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13285 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13287 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13288 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13289 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13290 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13291 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13292 | ssl_data5.cert_request_info = cert_request.get(); |
| 13293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13294 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13295 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13296 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13299 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13300 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13301 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13302 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13303 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13304 | |
| 13305 | // Complete the SSL handshake, which should abort due to requiring a |
| 13306 | // client certificate. |
| 13307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13308 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13309 | |
| 13310 | // Indicate that no certificate should be supplied. From the perspective |
| 13311 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13312 | // certificate, so this is the same as supply a |
| 13313 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13314 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13315 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13316 | |
| 13317 | // Ensure the certificate was added to the client auth cache before |
| 13318 | // allowing the connection to continue restarting. |
| 13319 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13320 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13321 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13322 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13323 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13324 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13325 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13326 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13327 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13328 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13329 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13330 | |
| 13331 | // Ensure that the client certificate is removed from the cache on a |
| 13332 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13333 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13334 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13335 | } |
| 13336 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13337 | // Ensure that a client certificate is removed from the SSL client auth |
| 13338 | // cache when: |
| 13339 | // 1) An HTTPS proxy is involved. |
| 13340 | // 3) The HTTPS proxy requests a client certificate. |
| 13341 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13342 | // proxy. |
| 13343 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13344 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13345 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13346 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13347 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13348 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13349 | |
| 13350 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13351 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13352 | |
| 13353 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13354 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13355 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13356 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13357 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13358 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13360 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13361 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13362 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13363 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13364 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13366 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13367 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13368 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13369 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13370 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13371 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13372 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13373 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13374 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13375 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13376 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13377 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13378 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13379 | requests[0].url = GURL("https://www.example.com/"); |
| 13380 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13381 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13382 | |
| 13383 | requests[1].url = GURL("http://www.example.com/"); |
| 13384 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13385 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13386 | |
| 13387 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13388 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13389 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13390 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13391 | |
| 13392 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13393 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13394 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13395 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13396 | |
| 13397 | // Complete the SSL handshake, which should abort due to requiring a |
| 13398 | // client certificate. |
| 13399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13400 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13401 | |
| 13402 | // Indicate that no certificate should be supplied. From the perspective |
| 13403 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13404 | // certificate, so this is the same as supply a |
| 13405 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13406 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13407 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13408 | |
| 13409 | // Ensure the certificate was added to the client auth cache before |
| 13410 | // allowing the connection to continue restarting. |
| 13411 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13412 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13413 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13414 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13415 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13416 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13417 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13418 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13419 | HostPortPair("www.example.com", 443), &client_cert, |
| 13420 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13421 | |
| 13422 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13423 | // then consume ssl_data3, which should also fail. The result code is |
| 13424 | // checked against what ssl_data3 should return. |
| 13425 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13426 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13427 | |
| 13428 | // Now that the new handshake has failed, ensure that the client |
| 13429 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13430 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13431 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13432 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13433 | HostPortPair("www.example.com", 443), &client_cert, |
| 13434 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13435 | } |
| 13436 | } |
| 13437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13438 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13439 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13440 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13442 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13443 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13444 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13445 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13446 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13447 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13448 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13449 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13450 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13451 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13452 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13453 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13454 | SpdySerializedFrame host1_resp_body( |
| 13455 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13456 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13457 | SpdySerializedFrame host2_resp_body( |
| 13458 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13459 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13460 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13461 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13462 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13463 | }; |
| 13464 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13465 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13466 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13467 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13468 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13469 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13470 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13471 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13472 | HttpRequestInfo request1; |
| 13473 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13474 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13475 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13476 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13478 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13480 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13481 | |
| 13482 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13483 | ASSERT_TRUE(response); |
| 13484 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13485 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13486 | |
| 13487 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13488 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13489 | EXPECT_EQ("hello!", response_data); |
| 13490 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13491 | // Preload mail.example.com into HostCache. |
| 13492 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13493 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13494 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13495 | std::unique_ptr<HostResolver::Request> request; |
| 13496 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13497 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13498 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13499 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13501 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13502 | |
| 13503 | HttpRequestInfo request2; |
| 13504 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13505 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13506 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13507 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13508 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13509 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13510 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13511 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13512 | |
| 13513 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13514 | ASSERT_TRUE(response); |
| 13515 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13516 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13517 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13518 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13519 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13520 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13521 | } |
| 13522 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13523 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13524 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13525 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13527 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13528 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13529 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13530 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13531 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13532 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13533 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13534 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13535 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13536 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13537 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13538 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13539 | SpdySerializedFrame host1_resp_body( |
| 13540 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13541 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13542 | SpdySerializedFrame host2_resp_body( |
| 13543 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13544 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13545 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13546 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13547 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13548 | }; |
| 13549 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13550 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13551 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13552 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13553 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13554 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13555 | |
| 13556 | TestCompletionCallback callback; |
| 13557 | HttpRequestInfo request1; |
| 13558 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13559 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13560 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13561 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13563 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13565 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13566 | |
| 13567 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13568 | ASSERT_TRUE(response); |
| 13569 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13570 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13571 | |
| 13572 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13573 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13574 | EXPECT_EQ("hello!", response_data); |
| 13575 | |
| 13576 | HttpRequestInfo request2; |
| 13577 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13578 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13579 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13580 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13582 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13584 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13585 | |
| 13586 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13587 | ASSERT_TRUE(response); |
| 13588 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13589 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13590 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13591 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13592 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13593 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13594 | } |
| 13595 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13596 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13597 | public: |
| 13598 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13599 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13600 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13601 | |
| 13602 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13603 | |
| 13604 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13605 | int Resolve(const RequestInfo& info, |
| 13606 | RequestPriority priority, |
| 13607 | AddressList* addresses, |
| 13608 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13609 | std::unique_ptr<Request>* out_req, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13610 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13611 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13612 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13613 | } |
| 13614 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13615 | int ResolveFromCache(const RequestInfo& info, |
| 13616 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13617 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13618 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13619 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13620 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13621 | return rv; |
| 13622 | } |
| 13623 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13624 | MockCachingHostResolver* GetMockHostResolver() { |
| 13625 | return &host_resolver_; |
| 13626 | } |
| 13627 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13628 | private: |
| 13629 | MockCachingHostResolver host_resolver_; |
| 13630 | const HostPortPair host_port_; |
| 13631 | }; |
| 13632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13633 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13634 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13635 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13636 | OneTimeCachingHostResolver host_resolver( |
| 13637 | HostPortPair("mail.example.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13638 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13639 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13640 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13642 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13643 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13644 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13645 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13646 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13647 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13648 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13649 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13650 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13651 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13652 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13653 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13654 | SpdySerializedFrame host1_resp_body( |
| 13655 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13656 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13657 | SpdySerializedFrame host2_resp_body( |
| 13658 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13659 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13660 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13661 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13662 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13663 | }; |
| 13664 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13665 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13666 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13667 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13668 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13669 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13670 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13671 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13672 | HttpRequestInfo request1; |
| 13673 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13674 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13675 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13676 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13678 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13680 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13681 | |
| 13682 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13683 | ASSERT_TRUE(response); |
| 13684 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13685 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13686 | |
| 13687 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13688 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13689 | EXPECT_EQ("hello!", response_data); |
| 13690 | |
| 13691 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13692 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13693 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13694 | std::unique_ptr<HostResolver::Request> request; |
| 13695 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13696 | callback.callback(), &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13699 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13700 | |
| 13701 | HttpRequestInfo request2; |
| 13702 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13703 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13704 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13705 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13706 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13707 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13709 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13710 | |
| 13711 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13712 | ASSERT_TRUE(response); |
| 13713 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13714 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13715 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13716 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13717 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13718 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13719 | } |
| 13720 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13721 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13722 | const std::string https_url = "https://www.example.org:8080/"; |
| 13723 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13724 | |
| 13725 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13726 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13727 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13728 | |
| 13729 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13730 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13731 | }; |
| 13732 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13733 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13734 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13735 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13736 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13737 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13738 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13739 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13740 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13741 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13742 | |
| 13743 | // HTTP GET for the HTTP URL |
| 13744 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13745 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13746 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13747 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13748 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13749 | }; |
| 13750 | |
| 13751 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13752 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13753 | MockRead(ASYNC, 2, "hello"), |
| 13754 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13755 | }; |
| 13756 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13757 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13758 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13759 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13760 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13761 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13763 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13764 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13767 | |
| 13768 | // Start the first transaction to set up the SpdySession |
| 13769 | HttpRequestInfo request1; |
| 13770 | request1.method = "GET"; |
| 13771 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13772 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13773 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13774 | TestCompletionCallback callback1; |
| 13775 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13776 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13777 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13778 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13779 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13780 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13781 | |
| 13782 | // Now, start the HTTP request |
| 13783 | HttpRequestInfo request2; |
| 13784 | request2.method = "GET"; |
| 13785 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13786 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13787 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13788 | TestCompletionCallback callback2; |
| 13789 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13790 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13791 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13792 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13793 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13794 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13795 | } |
| 13796 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13797 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13798 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13799 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13800 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13801 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13802 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13803 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13804 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13805 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13807 | |
| 13808 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13809 | // negotiated. |
| 13810 | StaticSocketDataProvider data; |
| 13811 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13812 | |
| 13813 | // 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] | 13814 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13815 | // mocked. This way the request relies on the alternate Job. |
| 13816 | StaticSocketDataProvider data_refused; |
| 13817 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13818 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13819 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13820 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13822 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13823 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13824 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13825 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13826 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13827 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13828 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13829 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13831 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13832 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13833 | TestCompletionCallback callback; |
| 13834 | |
| 13835 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13836 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13837 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13838 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13839 | } |
| 13840 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13841 | // 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] | 13842 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13843 | // succeeds, the request should succeed, even if the latter fails because |
| 13844 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13845 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13846 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13847 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13848 | |
| 13849 | // Negotiate HTTP/1.1 with alternative. |
| 13850 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13851 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13852 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13853 | |
| 13854 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13855 | // negotiated. |
| 13856 | StaticSocketDataProvider data; |
| 13857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13858 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13859 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13860 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13861 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13863 | |
| 13864 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13865 | MockWrite("GET / HTTP/1.1\r\n" |
| 13866 | "Host: www.example.org\r\n" |
| 13867 | "Connection: keep-alive\r\n\r\n"), |
| 13868 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13869 | "Host: www.example.org\r\n" |
| 13870 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13871 | }; |
| 13872 | |
| 13873 | MockRead http_reads[] = { |
| 13874 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13875 | MockRead("Content-Type: text/html\r\n"), |
| 13876 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13877 | MockRead("foobar"), |
| 13878 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13879 | MockRead("Content-Type: text/html\r\n"), |
| 13880 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13881 | MockRead("another"), |
| 13882 | }; |
| 13883 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13884 | http_writes, arraysize(http_writes)); |
| 13885 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13886 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13887 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13889 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13890 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13891 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13892 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13893 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13894 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13895 | |
| 13896 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13897 | HttpRequestInfo request1; |
| 13898 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13899 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13900 | request1.load_flags = 0; |
| 13901 | TestCompletionCallback callback1; |
| 13902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13903 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13904 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13905 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13906 | |
| 13907 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13908 | ASSERT_TRUE(response1); |
| 13909 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13910 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13911 | |
| 13912 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13913 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13914 | EXPECT_EQ("foobar", response_data1); |
| 13915 | |
| 13916 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13917 | // for alternative service. |
| 13918 | EXPECT_TRUE( |
| 13919 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13920 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13921 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13922 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13923 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13924 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13925 | HttpRequestInfo request2; |
| 13926 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13927 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13928 | request2.load_flags = 0; |
| 13929 | TestCompletionCallback callback2; |
| 13930 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13931 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13932 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13933 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13934 | |
| 13935 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13936 | ASSERT_TRUE(response2); |
| 13937 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13938 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13939 | |
| 13940 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13941 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13942 | EXPECT_EQ("another", response_data2); |
| 13943 | } |
| 13944 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13945 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13946 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13947 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13948 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13949 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13950 | HostPortPair alternative("alternative.example.org", 443); |
| 13951 | std::string origin_url = "https://origin.example.org:443"; |
| 13952 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13953 | |
| 13954 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13955 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13956 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13958 | |
| 13959 | // HTTP/1.1 data for |request1| and |request2|. |
| 13960 | MockWrite http_writes[] = { |
| 13961 | MockWrite( |
| 13962 | "GET / HTTP/1.1\r\n" |
| 13963 | "Host: alternative.example.org\r\n" |
| 13964 | "Connection: keep-alive\r\n\r\n"), |
| 13965 | MockWrite( |
| 13966 | "GET / HTTP/1.1\r\n" |
| 13967 | "Host: alternative.example.org\r\n" |
| 13968 | "Connection: keep-alive\r\n\r\n"), |
| 13969 | }; |
| 13970 | |
| 13971 | MockRead http_reads[] = { |
| 13972 | MockRead( |
| 13973 | "HTTP/1.1 200 OK\r\n" |
| 13974 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13975 | "Content-Length: 40\r\n\r\n" |
| 13976 | "first HTTP/1.1 response from alternative"), |
| 13977 | MockRead( |
| 13978 | "HTTP/1.1 200 OK\r\n" |
| 13979 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13980 | "Content-Length: 41\r\n\r\n" |
| 13981 | "second HTTP/1.1 response from alternative"), |
| 13982 | }; |
| 13983 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13984 | http_writes, arraysize(http_writes)); |
| 13985 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13986 | |
| 13987 | // This test documents that an alternate Job should not pool to an already |
| 13988 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13989 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13990 | StaticSocketDataProvider data_refused; |
| 13991 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13992 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13993 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13994 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13996 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13997 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13998 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13999 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14000 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14001 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14002 | |
| 14003 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14004 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14005 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14006 | request1.method = "GET"; |
| 14007 | request1.url = GURL(alternative_url); |
| 14008 | request1.load_flags = 0; |
| 14009 | TestCompletionCallback callback1; |
| 14010 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14011 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14012 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14013 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14014 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14015 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14016 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14017 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14018 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14019 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14020 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14021 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14022 | |
| 14023 | // Request for origin.example.org, which has an alternative service. This |
| 14024 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14025 | // 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] | 14026 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14027 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14028 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14029 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14030 | request2.method = "GET"; |
| 14031 | request2.url = GURL(origin_url); |
| 14032 | request2.load_flags = 0; |
| 14033 | TestCompletionCallback callback2; |
| 14034 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14035 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14036 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14037 | |
| 14038 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14039 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14040 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14041 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14042 | request3.method = "GET"; |
| 14043 | request3.url = GURL(alternative_url); |
| 14044 | request3.load_flags = 0; |
| 14045 | TestCompletionCallback callback3; |
| 14046 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14047 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14048 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14049 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14050 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14051 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14052 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14053 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14054 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14055 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14056 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14057 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14058 | } |
| 14059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14060 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14061 | const std::string https_url = "https://www.example.org:8080/"; |
| 14062 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14063 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14064 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14065 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14066 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14067 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14068 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14069 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14070 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14071 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14072 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14073 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14074 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14075 | |
| 14076 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14077 | SpdyHeaderBlock req2_block; |
| 14078 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14079 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14080 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14081 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14082 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14083 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14084 | |
| 14085 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14086 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14087 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14088 | }; |
| 14089 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14090 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14091 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14092 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14093 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14094 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14095 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14096 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14097 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14098 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14099 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14100 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14101 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14102 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14103 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14104 | CreateMockRead(wrapped_resp1, 4), |
| 14105 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14106 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14107 | CreateMockRead(resp2, 8), |
| 14108 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14109 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14110 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14111 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14112 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14113 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14114 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14115 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14116 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14117 | session_deps_.proxy_service = |
| 14118 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14119 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14120 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14121 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14122 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14123 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14124 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14125 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14127 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14128 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14129 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14130 | |
| 14131 | // Start the first transaction to set up the SpdySession |
| 14132 | HttpRequestInfo request1; |
| 14133 | request1.method = "GET"; |
| 14134 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14135 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14136 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14137 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14138 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14139 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14140 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14141 | data1.RunUntilPaused(); |
| 14142 | base::RunLoop().RunUntilIdle(); |
| 14143 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14144 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14145 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14146 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14147 | LoadTimingInfo load_timing_info1; |
| 14148 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14149 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14150 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14151 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14152 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14153 | HttpRequestInfo request2; |
| 14154 | request2.method = "GET"; |
| 14155 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14156 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14157 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14158 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14159 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14160 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14161 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14162 | data1.RunUntilPaused(); |
| 14163 | base::RunLoop().RunUntilIdle(); |
| 14164 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14165 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14166 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14167 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14168 | |
| 14169 | LoadTimingInfo load_timing_info2; |
| 14170 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14171 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14172 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14173 | // HTTP requests over a SPDY session should have a different connection |
| 14174 | // socket_log_id than requests over a tunnel. |
| 14175 | 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] | 14176 | } |
| 14177 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14178 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14179 | // that we do not pool other origins that resolve to the same IP when |
| 14180 | // the certificate does not match the new origin. |
| 14181 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14182 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14183 | const std::string url1 = "http://www.example.org/"; |
| 14184 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14185 | const std::string ip_addr = "1.2.3.4"; |
| 14186 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14187 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14188 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14189 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14190 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14191 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14192 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14193 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14194 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14195 | |
| 14196 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14197 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14198 | }; |
| 14199 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14200 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14201 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14202 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14203 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14204 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14205 | }; |
| 14206 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14207 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14208 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14209 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14210 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14211 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14212 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14213 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14214 | |
| 14215 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14216 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14217 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14218 | |
| 14219 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14220 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14221 | }; |
| 14222 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14223 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14224 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14225 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14226 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14227 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14228 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14229 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14230 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14231 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14232 | |
| 14233 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14234 | // all others direct. |
| 14235 | ProxyConfig proxy_config; |
| 14236 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14237 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14238 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 14239 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14240 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14241 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14242 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14243 | // Load a valid cert. Note, that this does not need to |
| 14244 | // be valid for proxy because the MockSSLClientSocket does |
| 14245 | // not actually verify it. But SpdySession will use this |
| 14246 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14247 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14248 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14250 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14251 | |
| 14252 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14253 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14255 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14256 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14257 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14258 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14259 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14260 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14261 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14262 | |
| 14263 | // Start the first transaction to set up the SpdySession |
| 14264 | HttpRequestInfo request1; |
| 14265 | request1.method = "GET"; |
| 14266 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14267 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14268 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14269 | TestCompletionCallback callback1; |
| 14270 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14271 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14272 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14273 | data1.RunUntilPaused(); |
| 14274 | base::RunLoop().RunUntilIdle(); |
| 14275 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14276 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14277 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14278 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14279 | |
| 14280 | // Now, start the HTTP request |
| 14281 | HttpRequestInfo request2; |
| 14282 | request2.method = "GET"; |
| 14283 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14284 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14285 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14286 | TestCompletionCallback callback2; |
| 14287 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14288 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14289 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14290 | |
| 14291 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14292 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14293 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14294 | } |
| 14295 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14296 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14297 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14298 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14299 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14300 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14301 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14302 | |
| 14303 | MockRead reads1[] = { |
| 14304 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14305 | }; |
| 14306 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14307 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14308 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14309 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14310 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14311 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14312 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14313 | }; |
| 14314 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14315 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14316 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14317 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14318 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14319 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14320 | }; |
| 14321 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14322 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14323 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14324 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14325 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14326 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14328 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14329 | |
| 14330 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14331 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14333 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14335 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14336 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14337 | |
| 14338 | // Start the first transaction to set up the SpdySession and verify that |
| 14339 | // connection was closed. |
| 14340 | HttpRequestInfo request1; |
| 14341 | request1.method = "GET"; |
| 14342 | request1.url = GURL(https_url); |
| 14343 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14344 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14345 | TestCompletionCallback callback1; |
| 14346 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14347 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14348 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14349 | |
| 14350 | // Now, start the second request and make sure it succeeds. |
| 14351 | HttpRequestInfo request2; |
| 14352 | request2.method = "GET"; |
| 14353 | request2.url = GURL(https_url); |
| 14354 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14355 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14356 | TestCompletionCallback callback2; |
| 14357 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14358 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14359 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14360 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14361 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14362 | } |
| 14363 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14364 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14365 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14366 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14367 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14368 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14369 | |
| 14370 | // Use two different hosts with different IPs so they don't get pooled. |
| 14371 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14372 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14374 | |
| 14375 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14376 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14377 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14378 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14381 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14382 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14383 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14384 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14385 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14386 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14387 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14388 | SpdySerializedFrame host1_resp_body( |
| 14389 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14390 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14391 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14392 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14393 | }; |
| 14394 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14395 | // Use a separate test instance for the separate SpdySession that will be |
| 14396 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14397 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14398 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14399 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14400 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14401 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14402 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14403 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14404 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14405 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14406 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14407 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14408 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14409 | SpdySerializedFrame host2_resp_body( |
| 14410 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14411 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14412 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14413 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14414 | }; |
| 14415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14416 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14417 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14418 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14419 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14420 | |
| 14421 | MockWrite http_write[] = { |
| 14422 | MockWrite("GET / HTTP/1.1\r\n" |
| 14423 | "Host: www.a.com\r\n" |
| 14424 | "Connection: keep-alive\r\n\r\n"), |
| 14425 | }; |
| 14426 | |
| 14427 | MockRead http_read[] = { |
| 14428 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14429 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14430 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14431 | MockRead("hello!"), |
| 14432 | }; |
| 14433 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14434 | http_write, arraysize(http_write)); |
| 14435 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14436 | |
| 14437 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14438 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14439 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14440 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14441 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14442 | |
| 14443 | TestCompletionCallback callback; |
| 14444 | HttpRequestInfo request1; |
| 14445 | request1.method = "GET"; |
| 14446 | request1.url = GURL("https://www.a.com/"); |
| 14447 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14448 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14449 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14450 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14451 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14453 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14454 | |
| 14455 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14456 | ASSERT_TRUE(response); |
| 14457 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14458 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14459 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14460 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14461 | |
| 14462 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14463 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14464 | EXPECT_EQ("hello!", response_data); |
| 14465 | trans.reset(); |
| 14466 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14467 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14468 | |
| 14469 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14470 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14471 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14472 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14473 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14474 | HttpRequestInfo request2; |
| 14475 | request2.method = "GET"; |
| 14476 | request2.url = GURL("https://www.b.com/"); |
| 14477 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14478 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14480 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14482 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14483 | |
| 14484 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14485 | ASSERT_TRUE(response); |
| 14486 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14487 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14488 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14489 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14490 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14491 | EXPECT_EQ("hello!", response_data); |
| 14492 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14493 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14494 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14495 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14496 | |
| 14497 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14498 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14499 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14500 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14501 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14502 | HttpRequestInfo request3; |
| 14503 | request3.method = "GET"; |
| 14504 | request3.url = GURL("http://www.a.com/"); |
| 14505 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14506 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14507 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14508 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14509 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14510 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14511 | |
| 14512 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14513 | ASSERT_TRUE(response); |
| 14514 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14515 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14516 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14517 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14518 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14519 | EXPECT_EQ("hello!", response_data); |
| 14520 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14521 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14522 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14523 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14524 | } |
| 14525 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14526 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14527 | HttpRequestInfo request; |
| 14528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14530 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14533 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14534 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14535 | StaticSocketDataProvider data; |
| 14536 | data.set_connect_data(mock_connect); |
| 14537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14538 | |
| 14539 | TestCompletionCallback callback; |
| 14540 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14541 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14543 | |
| 14544 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14545 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14546 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14547 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14548 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14549 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14550 | |
| 14551 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14552 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14553 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14554 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14555 | |
| 14556 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14557 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14558 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14559 | } |
| 14560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14561 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14562 | HttpRequestInfo request; |
| 14563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14564 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14565 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14566 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14567 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14568 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14569 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14570 | StaticSocketDataProvider data; |
| 14571 | data.set_connect_data(mock_connect); |
| 14572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14573 | |
| 14574 | TestCompletionCallback callback; |
| 14575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14578 | |
| 14579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14580 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14581 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14582 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14583 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14584 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14585 | |
| 14586 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14587 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14588 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14589 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14590 | |
| 14591 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14592 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14593 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14594 | } |
| 14595 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14596 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14597 | HttpRequestInfo request; |
| 14598 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14599 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14603 | |
| 14604 | MockWrite data_writes[] = { |
| 14605 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14606 | }; |
| 14607 | MockRead data_reads[] = { |
| 14608 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14609 | }; |
| 14610 | |
| 14611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14612 | data_writes, arraysize(data_writes)); |
| 14613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14614 | |
| 14615 | TestCompletionCallback callback; |
| 14616 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14617 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14619 | |
| 14620 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14621 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14622 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14623 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14624 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14625 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14626 | } |
| 14627 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14628 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14629 | HttpRequestInfo request; |
| 14630 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14631 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14632 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14635 | |
| 14636 | MockWrite data_writes[] = { |
| 14637 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14638 | }; |
| 14639 | MockRead data_reads[] = { |
| 14640 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14641 | }; |
| 14642 | |
| 14643 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14644 | data_writes, arraysize(data_writes)); |
| 14645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14646 | |
| 14647 | TestCompletionCallback callback; |
| 14648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14651 | |
| 14652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14653 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14654 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14655 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14656 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14657 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14658 | } |
| 14659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14660 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[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 | |
| 14668 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14669 | MockWrite( |
| 14670 | "GET / HTTP/1.1\r\n" |
| 14671 | "Host: www.example.org\r\n" |
| 14672 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14673 | }; |
| 14674 | MockRead data_reads[] = { |
| 14675 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14676 | }; |
| 14677 | |
| 14678 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14679 | data_writes, arraysize(data_writes)); |
| 14680 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14681 | |
| 14682 | TestCompletionCallback callback; |
| 14683 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14684 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14685 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14686 | |
| 14687 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14688 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14689 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14690 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14691 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14692 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14693 | } |
| 14694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14695 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[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 | |
| 14703 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14704 | MockWrite( |
| 14705 | "GET / HTTP/1.1\r\n" |
| 14706 | "Host: www.example.org\r\n" |
| 14707 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14708 | }; |
| 14709 | MockRead data_reads[] = { |
| 14710 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14711 | }; |
| 14712 | |
| 14713 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14714 | data_writes, arraysize(data_writes)); |
| 14715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14716 | |
| 14717 | TestCompletionCallback callback; |
| 14718 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14721 | |
| 14722 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14723 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14724 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14725 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14726 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14727 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14728 | } |
| 14729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14730 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[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 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14738 | |
| 14739 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14740 | MockWrite( |
| 14741 | "GET / HTTP/1.1\r\n" |
| 14742 | "Host: www.example.org\r\n" |
| 14743 | "Connection: keep-alive\r\n" |
| 14744 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14745 | }; |
| 14746 | MockRead data_reads[] = { |
| 14747 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14748 | "Content-Length: 5\r\n\r\n" |
| 14749 | "hello"), |
| 14750 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14751 | }; |
| 14752 | |
| 14753 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14754 | data_writes, arraysize(data_writes)); |
| 14755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14756 | |
| 14757 | TestCompletionCallback callback; |
| 14758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14759 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14761 | |
| 14762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14764 | |
| 14765 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14766 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14767 | std::string foo; |
| 14768 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14769 | EXPECT_EQ("bar", foo); |
| 14770 | } |
| 14771 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14772 | namespace { |
| 14773 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14774 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14775 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14776 | public base::SupportsWeakPtr<FakeStream> { |
| 14777 | public: |
| 14778 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14779 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14780 | |
| 14781 | RequestPriority priority() const { return priority_; } |
| 14782 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14783 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14784 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14785 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14786 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14787 | return ERR_IO_PENDING; |
| 14788 | } |
| 14789 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14790 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14791 | HttpResponseInfo* response, |
| 14792 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14793 | ADD_FAILURE(); |
| 14794 | return ERR_UNEXPECTED; |
| 14795 | } |
| 14796 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14797 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14798 | ADD_FAILURE(); |
| 14799 | return ERR_UNEXPECTED; |
| 14800 | } |
| 14801 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14802 | int ReadResponseBody(IOBuffer* buf, |
| 14803 | int buf_len, |
| 14804 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14805 | ADD_FAILURE(); |
| 14806 | return ERR_UNEXPECTED; |
| 14807 | } |
| 14808 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14809 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14810 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14811 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14812 | ADD_FAILURE(); |
| 14813 | return false; |
| 14814 | } |
| 14815 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14816 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14817 | ADD_FAILURE(); |
| 14818 | return false; |
| 14819 | } |
| 14820 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14821 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14822 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14823 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14824 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14825 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14826 | ADD_FAILURE(); |
| 14827 | return 0; |
| 14828 | } |
| 14829 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14830 | int64_t GetTotalSentBytes() const override { |
| 14831 | ADD_FAILURE(); |
| 14832 | return 0; |
| 14833 | } |
| 14834 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14835 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14836 | ADD_FAILURE(); |
| 14837 | return false; |
| 14838 | } |
| 14839 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14840 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14841 | |
| 14842 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14843 | ADD_FAILURE(); |
| 14844 | } |
| 14845 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14846 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14847 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 14848 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 14849 | TokenBindingType tb_type, |
| 14850 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14851 | ADD_FAILURE(); |
| 14852 | return ERR_NOT_IMPLEMENTED; |
| 14853 | } |
| 14854 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14855 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14856 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14857 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14858 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14859 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14860 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14861 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14862 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14863 | private: |
| 14864 | RequestPriority priority_; |
| 14865 | |
| 14866 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14867 | }; |
| 14868 | |
| 14869 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14870 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14871 | class FakeStreamRequest : public HttpStreamRequest, |
| 14872 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14873 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14874 | FakeStreamRequest(RequestPriority priority, |
| 14875 | HttpStreamRequest::Delegate* delegate) |
| 14876 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14877 | delegate_(delegate), |
| 14878 | websocket_stream_create_helper_(NULL) {} |
| 14879 | |
| 14880 | FakeStreamRequest(RequestPriority priority, |
| 14881 | HttpStreamRequest::Delegate* delegate, |
| 14882 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14883 | : priority_(priority), |
| 14884 | delegate_(delegate), |
| 14885 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14886 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14887 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14888 | |
| 14889 | RequestPriority priority() const { return priority_; } |
| 14890 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14891 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14892 | websocket_stream_create_helper() const { |
| 14893 | return websocket_stream_create_helper_; |
| 14894 | } |
| 14895 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14896 | // Create a new FakeStream and pass it to the request's |
| 14897 | // delegate. Returns a weak pointer to the FakeStream. |
| 14898 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14899 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14900 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14901 | // immediately delete |fake_stream|. |
| 14902 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14903 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14904 | return weak_stream; |
| 14905 | } |
| 14906 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14907 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14908 | ADD_FAILURE(); |
| 14909 | return ERR_UNEXPECTED; |
| 14910 | } |
| 14911 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14912 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14913 | ADD_FAILURE(); |
| 14914 | return LoadState(); |
| 14915 | } |
| 14916 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14917 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14918 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14919 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14920 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 14921 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14922 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14923 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14924 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14925 | const ConnectionAttempts& connection_attempts() const override { |
| 14926 | static ConnectionAttempts no_attempts; |
| 14927 | return no_attempts; |
| 14928 | } |
| 14929 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14930 | private: |
| 14931 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14932 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14933 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14934 | |
| 14935 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14936 | }; |
| 14937 | |
| 14938 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14939 | class FakeStreamFactory : public HttpStreamFactory { |
| 14940 | public: |
| 14941 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14942 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14943 | |
| 14944 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14945 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14946 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14947 | return last_stream_request_; |
| 14948 | } |
| 14949 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14950 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14951 | RequestPriority priority, |
| 14952 | const SSLConfig& server_ssl_config, |
| 14953 | const SSLConfig& proxy_ssl_config, |
| 14954 | HttpStreamRequest::Delegate* delegate, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14955 | const NetLogWithSource& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14956 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14957 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14958 | return fake_request; |
| 14959 | } |
| 14960 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14961 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14962 | const HttpRequestInfo& info, |
| 14963 | RequestPriority priority, |
| 14964 | const SSLConfig& server_ssl_config, |
| 14965 | const SSLConfig& proxy_ssl_config, |
| 14966 | HttpStreamRequest::Delegate* delegate, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14967 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14968 | NOTREACHED(); |
| 14969 | return nullptr; |
| 14970 | } |
| 14971 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14972 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14973 | const HttpRequestInfo& info, |
| 14974 | RequestPriority priority, |
| 14975 | const SSLConfig& server_ssl_config, |
| 14976 | const SSLConfig& proxy_ssl_config, |
| 14977 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14978 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14979 | const NetLogWithSource& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14980 | FakeStreamRequest* fake_request = |
| 14981 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14982 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14983 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14984 | } |
| 14985 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14986 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14987 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14988 | ADD_FAILURE(); |
| 14989 | } |
| 14990 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14991 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14992 | ADD_FAILURE(); |
| 14993 | return NULL; |
| 14994 | } |
| 14995 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 14996 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 14997 | const std::string& parent_absolute_name) const override { |
| 14998 | ADD_FAILURE(); |
| 14999 | } |
| 15000 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15001 | private: |
| 15002 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15003 | |
| 15004 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15005 | }; |
| 15006 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15007 | // TODO(ricea): Maybe unify this with the one in |
| 15008 | // url_request_http_job_unittest.cc ? |
| 15009 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15010 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15011 | FakeWebSocketBasicHandshakeStream( |
| 15012 | std::unique_ptr<ClientSocketHandle> connection, |
| 15013 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15014 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15015 | |
| 15016 | // Fake implementation of HttpStreamBase methods. |
| 15017 | // This ends up being quite "real" because this object has to really send data |
| 15018 | // on the mock socket. It might be easier to use the real implementation, but |
| 15019 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15020 | // difficult. |
| 15021 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15022 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15023 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15024 | const CompletionCallback& callback) override { |
| 15025 | state_.Initialize(request_info, priority, net_log, callback); |
| 15026 | return OK; |
| 15027 | } |
| 15028 | |
| 15029 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15030 | HttpResponseInfo* response, |
| 15031 | const CompletionCallback& callback) override { |
| 15032 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15033 | response, callback); |
| 15034 | } |
| 15035 | |
| 15036 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15037 | return parser()->ReadResponseHeaders(callback); |
| 15038 | } |
| 15039 | |
| 15040 | int ReadResponseBody(IOBuffer* buf, |
| 15041 | int buf_len, |
| 15042 | const CompletionCallback& callback) override { |
| 15043 | NOTREACHED(); |
| 15044 | return ERR_IO_PENDING; |
| 15045 | } |
| 15046 | |
| 15047 | void Close(bool not_reusable) override { |
| 15048 | if (parser()) |
| 15049 | parser()->Close(true); |
| 15050 | } |
| 15051 | |
| 15052 | bool IsResponseBodyComplete() const override { |
| 15053 | NOTREACHED(); |
| 15054 | return false; |
| 15055 | } |
| 15056 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15057 | bool IsConnectionReused() const override { |
| 15058 | NOTREACHED(); |
| 15059 | return false; |
| 15060 | } |
| 15061 | void SetConnectionReused() override { NOTREACHED(); } |
| 15062 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15063 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15064 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15065 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15066 | NOTREACHED(); |
| 15067 | return 0; |
| 15068 | } |
| 15069 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15070 | int64_t GetTotalSentBytes() const override { |
| 15071 | NOTREACHED(); |
| 15072 | return 0; |
| 15073 | } |
| 15074 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15075 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15076 | NOTREACHED(); |
| 15077 | return false; |
| 15078 | } |
| 15079 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15080 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15081 | |
| 15082 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15083 | NOTREACHED(); |
| 15084 | } |
| 15085 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15086 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15087 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15088 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15089 | TokenBindingType tb_type, |
| 15090 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15091 | ADD_FAILURE(); |
| 15092 | return ERR_NOT_IMPLEMENTED; |
| 15093 | } |
| 15094 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15095 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15096 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15097 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15098 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15099 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15100 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15101 | HttpStream* RenewStreamForAuth() override { |
| 15102 | NOTREACHED(); |
| 15103 | return nullptr; |
| 15104 | } |
| 15105 | |
| 15106 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15107 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15108 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15109 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15110 | } |
| 15111 | |
| 15112 | private: |
| 15113 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15114 | HttpBasicState state_; |
| 15115 | |
| 15116 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15117 | }; |
| 15118 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15119 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15120 | // worth doing. |
| 15121 | class FakeWebSocketStreamCreateHelper : |
| 15122 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15123 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15124 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15125 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15126 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15127 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15128 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15129 | } |
| 15130 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15131 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15132 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15133 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15134 | NOTREACHED(); |
| 15135 | return NULL; |
| 15136 | }; |
| 15137 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15138 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15139 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15140 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15141 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15142 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15143 | } |
| 15144 | }; |
| 15145 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15146 | } // namespace |
| 15147 | |
| 15148 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15149 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15150 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15152 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15153 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15154 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15155 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15156 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15157 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15158 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15159 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15160 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15161 | TestCompletionCallback callback; |
| 15162 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15163 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15164 | |
| 15165 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15166 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15167 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15168 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15169 | } |
| 15170 | |
| 15171 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15172 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15173 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15175 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15176 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15177 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15178 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15179 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15180 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15181 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15182 | TestCompletionCallback callback; |
| 15183 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15184 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15185 | |
| 15186 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15187 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15188 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15189 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15190 | |
| 15191 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15192 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15193 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15194 | } |
| 15195 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15196 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15197 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15198 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15199 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15200 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15201 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15202 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15203 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15204 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15205 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15206 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15207 | TestCompletionCallback callback; |
| 15208 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15209 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15210 | |
| 15211 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15212 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15213 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15214 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15215 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15216 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15217 | |
| 15218 | trans.SetPriority(LOWEST); |
| 15219 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15220 | } |
| 15221 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15222 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15223 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15224 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15225 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15226 | std::string test_cases[] = {"ws://www.example.org/", |
| 15227 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15228 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15230 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15231 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15232 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15233 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15234 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15235 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15236 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15237 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15238 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15239 | &websocket_stream_create_helper); |
| 15240 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15241 | TestCompletionCallback callback; |
| 15242 | request.method = "GET"; |
| 15243 | request.url = GURL(test_cases[i]); |
| 15244 | |
| 15245 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15246 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15247 | |
| 15248 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15249 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15250 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15251 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15252 | fake_request->websocket_stream_create_helper()); |
| 15253 | } |
| 15254 | } |
| 15255 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15256 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15257 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15258 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15259 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15260 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15261 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15262 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15263 | |
| 15264 | // Set up SSL request. |
| 15265 | |
| 15266 | HttpRequestInfo ssl_request; |
| 15267 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15268 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15269 | |
| 15270 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15271 | MockWrite( |
| 15272 | "GET / HTTP/1.1\r\n" |
| 15273 | "Host: www.example.org\r\n" |
| 15274 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15275 | }; |
| 15276 | MockRead ssl_reads[] = { |
| 15277 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15278 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15279 | MockRead("hello world"), |
| 15280 | MockRead(SYNCHRONOUS, OK), |
| 15281 | }; |
| 15282 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15283 | ssl_writes, arraysize(ssl_writes)); |
| 15284 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15285 | |
| 15286 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15287 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15288 | |
| 15289 | // Set up HTTP request. |
| 15290 | |
| 15291 | HttpRequestInfo http_request; |
| 15292 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15293 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15294 | |
| 15295 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15296 | MockWrite( |
| 15297 | "GET / HTTP/1.1\r\n" |
| 15298 | "Host: www.example.org\r\n" |
| 15299 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15300 | }; |
| 15301 | MockRead http_reads[] = { |
| 15302 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15303 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15304 | MockRead("falafel"), |
| 15305 | MockRead(SYNCHRONOUS, OK), |
| 15306 | }; |
| 15307 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15308 | http_writes, arraysize(http_writes)); |
| 15309 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15312 | |
| 15313 | // Start the SSL request. |
| 15314 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15315 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15316 | ASSERT_EQ(ERR_IO_PENDING, |
| 15317 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15318 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15319 | |
| 15320 | // Start the HTTP request. Pool should stall. |
| 15321 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15322 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15323 | ASSERT_EQ(ERR_IO_PENDING, |
| 15324 | http_trans.Start(&http_request, http_callback.callback(), |
| 15325 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15326 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15327 | |
| 15328 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15329 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15330 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15331 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15332 | EXPECT_EQ("hello world", response_data); |
| 15333 | |
| 15334 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15335 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15336 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15337 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15338 | |
| 15339 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15340 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15341 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15342 | EXPECT_EQ("falafel", response_data); |
| 15343 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15344 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15345 | } |
| 15346 | |
| 15347 | // Tests that when a SSL connection is established but there's no corresponding |
| 15348 | // request that needs it, the new socket is closed if the transport socket pool |
| 15349 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15350 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15351 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15352 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15353 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15354 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15355 | |
| 15356 | // Set up an ssl request. |
| 15357 | |
| 15358 | HttpRequestInfo ssl_request; |
| 15359 | ssl_request.method = "GET"; |
| 15360 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15361 | |
| 15362 | // No data will be sent on the SSL socket. |
| 15363 | StaticSocketDataProvider ssl_data; |
| 15364 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15365 | |
| 15366 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15368 | |
| 15369 | // Set up HTTP request. |
| 15370 | |
| 15371 | HttpRequestInfo http_request; |
| 15372 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15373 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15374 | |
| 15375 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15376 | MockWrite( |
| 15377 | "GET / HTTP/1.1\r\n" |
| 15378 | "Host: www.example.org\r\n" |
| 15379 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15380 | }; |
| 15381 | MockRead http_reads[] = { |
| 15382 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15383 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15384 | MockRead("falafel"), |
| 15385 | MockRead(SYNCHRONOUS, OK), |
| 15386 | }; |
| 15387 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15388 | http_writes, arraysize(http_writes)); |
| 15389 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15390 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15392 | |
| 15393 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15394 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15395 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15396 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15397 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15398 | |
| 15399 | // Start the HTTP request. Pool should stall. |
| 15400 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15401 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15402 | ASSERT_EQ(ERR_IO_PENDING, |
| 15403 | http_trans.Start(&http_request, http_callback.callback(), |
| 15404 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15405 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15406 | |
| 15407 | // The SSL connection will automatically be closed once the connection is |
| 15408 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15409 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15410 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15411 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15412 | EXPECT_EQ("falafel", response_data); |
| 15413 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15414 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15415 | } |
| 15416 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15417 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15418 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15419 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15420 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15421 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15422 | |
| 15423 | HttpRequestInfo request; |
| 15424 | request.method = "POST"; |
| 15425 | request.url = GURL("http://www.foo.com/"); |
| 15426 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15427 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15429 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15430 | // Send headers successfully, but get an error while sending the body. |
| 15431 | MockWrite data_writes[] = { |
| 15432 | MockWrite("POST / HTTP/1.1\r\n" |
| 15433 | "Host: www.foo.com\r\n" |
| 15434 | "Connection: keep-alive\r\n" |
| 15435 | "Content-Length: 3\r\n\r\n"), |
| 15436 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15437 | }; |
| 15438 | |
| 15439 | MockRead data_reads[] = { |
| 15440 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15441 | MockRead("hello world"), |
| 15442 | MockRead(SYNCHRONOUS, OK), |
| 15443 | }; |
| 15444 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15445 | arraysize(data_writes)); |
| 15446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15447 | |
| 15448 | TestCompletionCallback callback; |
| 15449 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15450 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15452 | |
| 15453 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15454 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15456 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15457 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15458 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15459 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15460 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15461 | |
| 15462 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15463 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15465 | EXPECT_EQ("hello world", response_data); |
| 15466 | } |
| 15467 | |
| 15468 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15469 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15470 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15471 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15473 | MockWrite data_writes[] = { |
| 15474 | MockWrite("GET / HTTP/1.1\r\n" |
| 15475 | "Host: www.foo.com\r\n" |
| 15476 | "Connection: keep-alive\r\n\r\n"), |
| 15477 | MockWrite("POST / HTTP/1.1\r\n" |
| 15478 | "Host: www.foo.com\r\n" |
| 15479 | "Connection: keep-alive\r\n" |
| 15480 | "Content-Length: 3\r\n\r\n"), |
| 15481 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15482 | }; |
| 15483 | |
| 15484 | MockRead data_reads[] = { |
| 15485 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15486 | "Content-Length: 14\r\n\r\n"), |
| 15487 | MockRead("first response"), |
| 15488 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15489 | "Content-Length: 15\r\n\r\n"), |
| 15490 | MockRead("second response"), |
| 15491 | MockRead(SYNCHRONOUS, OK), |
| 15492 | }; |
| 15493 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15494 | arraysize(data_writes)); |
| 15495 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15496 | |
| 15497 | TestCompletionCallback callback; |
| 15498 | HttpRequestInfo request1; |
| 15499 | request1.method = "GET"; |
| 15500 | request1.url = GURL("http://www.foo.com/"); |
| 15501 | request1.load_flags = 0; |
| 15502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15503 | std::unique_ptr<HttpNetworkTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15504 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15505 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15507 | |
| 15508 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15510 | |
| 15511 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15512 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15513 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15514 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15515 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15516 | |
| 15517 | std::string response_data1; |
| 15518 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15519 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15520 | EXPECT_EQ("first response", response_data1); |
| 15521 | // Delete the transaction to release the socket back into the socket pool. |
| 15522 | trans1.reset(); |
| 15523 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15524 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15525 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15526 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15527 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15528 | |
| 15529 | HttpRequestInfo request2; |
| 15530 | request2.method = "POST"; |
| 15531 | request2.url = GURL("http://www.foo.com/"); |
| 15532 | request2.upload_data_stream = &upload_data_stream; |
| 15533 | request2.load_flags = 0; |
| 15534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15535 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15536 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15538 | |
| 15539 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15542 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15543 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15544 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15545 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15546 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15547 | |
| 15548 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15549 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15551 | EXPECT_EQ("second response", response_data2); |
| 15552 | } |
| 15553 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15554 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15555 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15556 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15557 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15558 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15559 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15560 | |
| 15561 | HttpRequestInfo request; |
| 15562 | request.method = "POST"; |
| 15563 | request.url = GURL("http://www.foo.com/"); |
| 15564 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15565 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15566 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15567 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15568 | // Send headers successfully, but get an error while sending the body. |
| 15569 | MockWrite data_writes[] = { |
| 15570 | MockWrite("POST / HTTP/1.1\r\n" |
| 15571 | "Host: www.foo.com\r\n" |
| 15572 | "Connection: keep-alive\r\n" |
| 15573 | "Content-Length: 3\r\n\r\n" |
| 15574 | "fo"), |
| 15575 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15576 | }; |
| 15577 | |
| 15578 | MockRead data_reads[] = { |
| 15579 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15580 | MockRead("hello world"), |
| 15581 | MockRead(SYNCHRONOUS, OK), |
| 15582 | }; |
| 15583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15584 | arraysize(data_writes)); |
| 15585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15586 | |
| 15587 | TestCompletionCallback callback; |
| 15588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15591 | |
| 15592 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15596 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15597 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15598 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15599 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15600 | |
| 15601 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15602 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15603 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15604 | EXPECT_EQ("hello world", response_data); |
| 15605 | } |
| 15606 | |
| 15607 | // This tests the more common case than the previous test, where headers and |
| 15608 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15609 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15610 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15611 | |
| 15612 | HttpRequestInfo request; |
| 15613 | request.method = "POST"; |
| 15614 | request.url = GURL("http://www.foo.com/"); |
| 15615 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15616 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15617 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15618 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15619 | // Send headers successfully, but get an error while sending the body. |
| 15620 | MockWrite data_writes[] = { |
| 15621 | MockWrite("POST / HTTP/1.1\r\n" |
| 15622 | "Host: www.foo.com\r\n" |
| 15623 | "Connection: keep-alive\r\n" |
| 15624 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15625 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15626 | }; |
| 15627 | |
| 15628 | MockRead data_reads[] = { |
| 15629 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15630 | MockRead("hello world"), |
| 15631 | MockRead(SYNCHRONOUS, OK), |
| 15632 | }; |
| 15633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15634 | arraysize(data_writes)); |
| 15635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15636 | |
| 15637 | TestCompletionCallback callback; |
| 15638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15641 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15642 | // they can't be merged with the body in a single send. Not currently |
| 15643 | // necessary since a chunked body is never merged with headers, but this makes |
| 15644 | // the test more future proof. |
| 15645 | base::RunLoop().RunUntilIdle(); |
| 15646 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15647 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15648 | |
| 15649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15652 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15653 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15654 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15655 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15656 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15657 | |
| 15658 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15659 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15660 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15661 | EXPECT_EQ("hello world", response_data); |
| 15662 | } |
| 15663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15664 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15665 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15666 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15667 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15668 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15669 | |
| 15670 | HttpRequestInfo request; |
| 15671 | request.method = "POST"; |
| 15672 | request.url = GURL("http://www.foo.com/"); |
| 15673 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15677 | |
| 15678 | MockWrite data_writes[] = { |
| 15679 | MockWrite("POST / HTTP/1.1\r\n" |
| 15680 | "Host: www.foo.com\r\n" |
| 15681 | "Connection: keep-alive\r\n" |
| 15682 | "Content-Length: 3\r\n\r\n"), |
| 15683 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15684 | }; |
| 15685 | |
| 15686 | MockRead data_reads[] = { |
| 15687 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15688 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15689 | MockRead("hello world"), |
| 15690 | MockRead(SYNCHRONOUS, OK), |
| 15691 | }; |
| 15692 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15693 | arraysize(data_writes)); |
| 15694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15695 | |
| 15696 | TestCompletionCallback callback; |
| 15697 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15698 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15700 | |
| 15701 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15704 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15705 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15706 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15707 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15708 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15709 | |
| 15710 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15711 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15713 | EXPECT_EQ("hello world", response_data); |
| 15714 | } |
| 15715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15716 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15717 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15718 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15719 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15720 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15721 | |
| 15722 | HttpRequestInfo request; |
| 15723 | request.method = "POST"; |
| 15724 | request.url = GURL("http://www.foo.com/"); |
| 15725 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15729 | // Send headers successfully, but get an error while sending the body. |
| 15730 | MockWrite data_writes[] = { |
| 15731 | MockWrite("POST / HTTP/1.1\r\n" |
| 15732 | "Host: www.foo.com\r\n" |
| 15733 | "Connection: keep-alive\r\n" |
| 15734 | "Content-Length: 3\r\n\r\n"), |
| 15735 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15736 | }; |
| 15737 | |
| 15738 | MockRead data_reads[] = { |
| 15739 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15740 | MockRead("hello world"), |
| 15741 | MockRead(SYNCHRONOUS, OK), |
| 15742 | }; |
| 15743 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15744 | arraysize(data_writes)); |
| 15745 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15746 | |
| 15747 | TestCompletionCallback callback; |
| 15748 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15749 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15751 | |
| 15752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15753 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15754 | } |
| 15755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15756 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15757 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15758 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15759 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15760 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15761 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15762 | |
| 15763 | HttpRequestInfo request; |
| 15764 | request.method = "POST"; |
| 15765 | request.url = GURL("http://www.foo.com/"); |
| 15766 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15770 | // Send headers successfully, but get an error while sending the body. |
| 15771 | MockWrite data_writes[] = { |
| 15772 | MockWrite("POST / HTTP/1.1\r\n" |
| 15773 | "Host: www.foo.com\r\n" |
| 15774 | "Connection: keep-alive\r\n" |
| 15775 | "Content-Length: 3\r\n\r\n"), |
| 15776 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15777 | }; |
| 15778 | |
| 15779 | MockRead data_reads[] = { |
| 15780 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15781 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15782 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15783 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15784 | MockRead(SYNCHRONOUS, OK), |
| 15785 | }; |
| 15786 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15787 | arraysize(data_writes)); |
| 15788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15789 | |
| 15790 | TestCompletionCallback callback; |
| 15791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15794 | |
| 15795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15796 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15797 | } |
| 15798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15799 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15800 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15801 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15802 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15803 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15804 | |
| 15805 | HttpRequestInfo request; |
| 15806 | request.method = "POST"; |
| 15807 | request.url = GURL("http://www.foo.com/"); |
| 15808 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15812 | // Send headers successfully, but get an error while sending the body. |
| 15813 | MockWrite data_writes[] = { |
| 15814 | MockWrite("POST / HTTP/1.1\r\n" |
| 15815 | "Host: www.foo.com\r\n" |
| 15816 | "Connection: keep-alive\r\n" |
| 15817 | "Content-Length: 3\r\n\r\n"), |
| 15818 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15819 | }; |
| 15820 | |
| 15821 | MockRead data_reads[] = { |
| 15822 | MockRead("HTTP 0.9 rocks!"), |
| 15823 | MockRead(SYNCHRONOUS, OK), |
| 15824 | }; |
| 15825 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15826 | arraysize(data_writes)); |
| 15827 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15828 | |
| 15829 | TestCompletionCallback callback; |
| 15830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15831 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15833 | |
| 15834 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15835 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15836 | } |
| 15837 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15838 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15839 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15840 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15841 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15842 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15843 | |
| 15844 | HttpRequestInfo request; |
| 15845 | request.method = "POST"; |
| 15846 | request.url = GURL("http://www.foo.com/"); |
| 15847 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15848 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15850 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15851 | // Send headers successfully, but get an error while sending the body. |
| 15852 | MockWrite data_writes[] = { |
| 15853 | MockWrite("POST / HTTP/1.1\r\n" |
| 15854 | "Host: www.foo.com\r\n" |
| 15855 | "Connection: keep-alive\r\n" |
| 15856 | "Content-Length: 3\r\n\r\n"), |
| 15857 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15858 | }; |
| 15859 | |
| 15860 | MockRead data_reads[] = { |
| 15861 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15862 | MockRead(SYNCHRONOUS, OK), |
| 15863 | }; |
| 15864 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15865 | arraysize(data_writes)); |
| 15866 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15867 | |
| 15868 | TestCompletionCallback callback; |
| 15869 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15870 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15872 | |
| 15873 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15874 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15875 | } |
| 15876 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15877 | // Verify that proxy headers are not sent to the destination server when |
| 15878 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15879 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15880 | HttpRequestInfo request; |
| 15881 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15882 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15883 | AddWebSocketHeaders(&request.extra_headers); |
| 15884 | |
| 15885 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15886 | session_deps_.proxy_service = |
| 15887 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15890 | |
| 15891 | // Since a proxy is configured, try to establish a tunnel. |
| 15892 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15893 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15894 | "Host: www.example.org:443\r\n" |
| 15895 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15896 | |
| 15897 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15898 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15899 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15900 | "Host: www.example.org:443\r\n" |
| 15901 | "Proxy-Connection: keep-alive\r\n" |
| 15902 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15903 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15904 | MockWrite("GET / HTTP/1.1\r\n" |
| 15905 | "Host: www.example.org\r\n" |
| 15906 | "Connection: Upgrade\r\n" |
| 15907 | "Upgrade: websocket\r\n" |
| 15908 | "Origin: http://www.example.org\r\n" |
| 15909 | "Sec-WebSocket-Version: 13\r\n" |
| 15910 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15911 | }; |
| 15912 | |
| 15913 | // The proxy responds to the connect with a 407, using a persistent |
| 15914 | // connection. |
| 15915 | MockRead data_reads[] = { |
| 15916 | // No credentials. |
| 15917 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15918 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15919 | MockRead("Content-Length: 0\r\n"), |
| 15920 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15921 | |
| 15922 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15923 | |
| 15924 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15925 | MockRead("Upgrade: websocket\r\n"), |
| 15926 | MockRead("Connection: Upgrade\r\n"), |
| 15927 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15928 | }; |
| 15929 | |
| 15930 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15931 | arraysize(data_writes)); |
| 15932 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15933 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15936 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15937 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15938 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15939 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15940 | &websocket_stream_create_helper); |
| 15941 | |
| 15942 | { |
| 15943 | TestCompletionCallback callback; |
| 15944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15945 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15947 | |
| 15948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15949 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15950 | } |
| 15951 | |
| 15952 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15953 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15954 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15955 | EXPECT_EQ(407, response->headers->response_code()); |
| 15956 | |
| 15957 | { |
| 15958 | TestCompletionCallback callback; |
| 15959 | |
| 15960 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15961 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15963 | |
| 15964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15965 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15966 | } |
| 15967 | |
| 15968 | response = trans->GetResponseInfo(); |
| 15969 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15970 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15971 | |
| 15972 | EXPECT_EQ(101, response->headers->response_code()); |
| 15973 | |
| 15974 | trans.reset(); |
| 15975 | session->CloseAllConnections(); |
| 15976 | } |
| 15977 | |
| 15978 | // Verify that proxy headers are not sent to the destination server when |
| 15979 | // establishing a tunnel for an insecure WebSocket connection. |
| 15980 | // This requires the authentication info to be injected into the auth cache |
| 15981 | // due to crbug.com/395064 |
| 15982 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15983 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15984 | HttpRequestInfo request; |
| 15985 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15986 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15987 | AddWebSocketHeaders(&request.extra_headers); |
| 15988 | |
| 15989 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15990 | session_deps_.proxy_service = |
| 15991 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15992 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15994 | |
| 15995 | MockWrite data_writes[] = { |
| 15996 | // Try to establish a tunnel for the WebSocket connection, with |
| 15997 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15998 | // they cannot and will not use the same TCP/IP connection as the |
| 15999 | // preflight HTTP request. |
| 16000 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16001 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16002 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16003 | "Proxy-Connection: keep-alive\r\n" |
| 16004 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16005 | |
| 16006 | MockWrite( |
| 16007 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16008 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16009 | "Connection: Upgrade\r\n" |
| 16010 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16011 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16012 | "Sec-WebSocket-Version: 13\r\n" |
| 16013 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16014 | }; |
| 16015 | |
| 16016 | MockRead data_reads[] = { |
| 16017 | // HTTP CONNECT with credentials. |
| 16018 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16019 | |
| 16020 | // WebSocket connection established inside tunnel. |
| 16021 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16022 | MockRead("Upgrade: websocket\r\n"), |
| 16023 | MockRead("Connection: Upgrade\r\n"), |
| 16024 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16025 | }; |
| 16026 | |
| 16027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16028 | arraysize(data_writes)); |
| 16029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16030 | |
| 16031 | session->http_auth_cache()->Add( |
| 16032 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16033 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16035 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16037 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16038 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16039 | &websocket_stream_create_helper); |
| 16040 | |
| 16041 | TestCompletionCallback callback; |
| 16042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16043 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16045 | |
| 16046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16047 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16048 | |
| 16049 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16050 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16051 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16052 | |
| 16053 | EXPECT_EQ(101, response->headers->response_code()); |
| 16054 | |
| 16055 | trans.reset(); |
| 16056 | session->CloseAllConnections(); |
| 16057 | } |
| 16058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16059 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16060 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16061 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16062 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16063 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16064 | |
| 16065 | HttpRequestInfo request; |
| 16066 | request.method = "POST"; |
| 16067 | request.url = GURL("http://www.foo.com/"); |
| 16068 | request.upload_data_stream = &upload_data_stream; |
| 16069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16072 | MockWrite data_writes[] = { |
| 16073 | MockWrite("POST / HTTP/1.1\r\n" |
| 16074 | "Host: www.foo.com\r\n" |
| 16075 | "Connection: keep-alive\r\n" |
| 16076 | "Content-Length: 3\r\n\r\n"), |
| 16077 | MockWrite("foo"), |
| 16078 | }; |
| 16079 | |
| 16080 | MockRead data_reads[] = { |
| 16081 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16082 | MockRead(SYNCHRONOUS, OK), |
| 16083 | }; |
| 16084 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16085 | arraysize(data_writes)); |
| 16086 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16087 | |
| 16088 | TestCompletionCallback callback; |
| 16089 | |
| 16090 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16091 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16092 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16093 | |
| 16094 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16095 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16096 | |
| 16097 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16098 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16099 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16100 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16101 | } |
| 16102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16103 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16104 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16105 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16106 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16107 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16108 | |
| 16109 | HttpRequestInfo request; |
| 16110 | request.method = "POST"; |
| 16111 | request.url = GURL("http://www.foo.com/"); |
| 16112 | request.upload_data_stream = &upload_data_stream; |
| 16113 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16114 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16116 | MockWrite data_writes[] = { |
| 16117 | MockWrite("POST / HTTP/1.1\r\n" |
| 16118 | "Host: www.foo.com\r\n" |
| 16119 | "Connection: keep-alive\r\n" |
| 16120 | "Content-Length: 3\r\n\r\n"), |
| 16121 | MockWrite("foo"), |
| 16122 | }; |
| 16123 | |
| 16124 | MockRead data_reads[] = { |
| 16125 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16126 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16127 | MockRead(SYNCHRONOUS, OK), |
| 16128 | }; |
| 16129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16130 | arraysize(data_writes)); |
| 16131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16132 | |
| 16133 | TestCompletionCallback callback; |
| 16134 | |
| 16135 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16136 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16137 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16138 | |
| 16139 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16140 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16141 | |
| 16142 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16143 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16144 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16145 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16146 | } |
| 16147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16148 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16149 | ChunkedUploadDataStream upload_data_stream(0); |
| 16150 | |
| 16151 | HttpRequestInfo request; |
| 16152 | request.method = "POST"; |
| 16153 | request.url = GURL("http://www.foo.com/"); |
| 16154 | request.upload_data_stream = &upload_data_stream; |
| 16155 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16158 | // Send headers successfully, but get an error while sending the body. |
| 16159 | MockWrite data_writes[] = { |
| 16160 | MockWrite("POST / HTTP/1.1\r\n" |
| 16161 | "Host: www.foo.com\r\n" |
| 16162 | "Connection: keep-alive\r\n" |
| 16163 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16164 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16165 | }; |
| 16166 | |
| 16167 | MockRead data_reads[] = { |
| 16168 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16169 | MockRead(SYNCHRONOUS, OK), |
| 16170 | }; |
| 16171 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16172 | arraysize(data_writes)); |
| 16173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16174 | |
| 16175 | TestCompletionCallback callback; |
| 16176 | |
| 16177 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16178 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16179 | |
| 16180 | base::RunLoop().RunUntilIdle(); |
| 16181 | upload_data_stream.AppendData("f", 1, false); |
| 16182 | |
| 16183 | base::RunLoop().RunUntilIdle(); |
| 16184 | upload_data_stream.AppendData("oo", 2, true); |
| 16185 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16186 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16187 | |
| 16188 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16189 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16190 | |
| 16191 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16192 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16193 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16194 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16195 | } |
| 16196 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16197 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16198 | // the unthrottled state are not blocked. |
| 16199 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16200 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16201 | std::unique_ptr<HttpNetworkSession> session( |
| 16202 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16203 | |
| 16204 | // Send a simple request and make sure it goes through. |
| 16205 | HttpRequestInfo request; |
| 16206 | request.method = "GET"; |
| 16207 | request.url = GURL("http://www.example.org/"); |
| 16208 | |
| 16209 | std::unique_ptr<HttpTransaction> trans( |
| 16210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16211 | |
| 16212 | MockWrite data_writes[] = { |
| 16213 | MockWrite("GET / HTTP/1.1\r\n" |
| 16214 | "Host: www.example.org\r\n" |
| 16215 | "Connection: keep-alive\r\n\r\n"), |
| 16216 | }; |
| 16217 | MockRead data_reads[] = { |
| 16218 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16219 | MockRead(SYNCHRONOUS, OK), |
| 16220 | }; |
| 16221 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16222 | arraysize(data_writes)); |
| 16223 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16224 | |
| 16225 | TestCompletionCallback callback; |
| 16226 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16227 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16228 | } |
| 16229 | |
| 16230 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16231 | // when the throttle is unblocked. |
| 16232 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16233 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16234 | std::unique_ptr<HttpNetworkSession> session( |
| 16235 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16236 | |
| 16237 | // Send a simple request and make sure it goes through. |
| 16238 | HttpRequestInfo request; |
| 16239 | request.method = "GET"; |
| 16240 | request.url = GURL("http://www.example.org/"); |
| 16241 | |
| 16242 | MockWrite data_writes[] = { |
| 16243 | MockWrite("GET / HTTP/1.1\r\n" |
| 16244 | "Host: www.example.org\r\n" |
| 16245 | "Connection: keep-alive\r\n\r\n"), |
| 16246 | }; |
| 16247 | MockRead data_reads[] = { |
| 16248 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16249 | MockRead(SYNCHRONOUS, OK), |
| 16250 | }; |
| 16251 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16252 | arraysize(data_writes)); |
| 16253 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16254 | |
| 16255 | // Start a request that will be throttled at start; confirm it |
| 16256 | // doesn't complete. |
| 16257 | throttler->set_throttle_new_requests(true); |
| 16258 | std::unique_ptr<HttpTransaction> trans( |
| 16259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16260 | |
| 16261 | TestCompletionCallback callback; |
| 16262 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16264 | |
| 16265 | base::RunLoop().RunUntilIdle(); |
| 16266 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16267 | EXPECT_FALSE(callback.have_result()); |
| 16268 | |
| 16269 | // Confirm the request goes on to complete when unthrottled. |
| 16270 | throttler->UnthrottleAllRequests(); |
| 16271 | base::RunLoop().RunUntilIdle(); |
| 16272 | ASSERT_TRUE(callback.have_result()); |
| 16273 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16274 | } |
| 16275 | |
| 16276 | // Destroy a request while it's throttled. |
| 16277 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16278 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16279 | std::unique_ptr<HttpNetworkSession> session( |
| 16280 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16281 | |
| 16282 | // Send a simple request and make sure it goes through. |
| 16283 | HttpRequestInfo request; |
| 16284 | request.method = "GET"; |
| 16285 | request.url = GURL("http://www.example.org/"); |
| 16286 | |
| 16287 | MockWrite data_writes[] = { |
| 16288 | MockWrite("GET / HTTP/1.1\r\n" |
| 16289 | "Host: www.example.org\r\n" |
| 16290 | "Connection: keep-alive\r\n\r\n"), |
| 16291 | }; |
| 16292 | MockRead data_reads[] = { |
| 16293 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16294 | MockRead(SYNCHRONOUS, OK), |
| 16295 | }; |
| 16296 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16297 | arraysize(data_writes)); |
| 16298 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16299 | |
| 16300 | // Start a request that will be throttled at start; confirm it |
| 16301 | // doesn't complete. |
| 16302 | throttler->set_throttle_new_requests(true); |
| 16303 | std::unique_ptr<HttpTransaction> trans( |
| 16304 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16305 | |
| 16306 | TestCompletionCallback callback; |
| 16307 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16308 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16309 | |
| 16310 | base::RunLoop().RunUntilIdle(); |
| 16311 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16312 | EXPECT_FALSE(callback.have_result()); |
| 16313 | |
| 16314 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16315 | trans.reset(); |
| 16316 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16317 | } |
| 16318 | |
| 16319 | // Confirm the throttler receives SetPriority calls. |
| 16320 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16321 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16322 | std::unique_ptr<HttpNetworkSession> session( |
| 16323 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16324 | |
| 16325 | // Send a simple request and make sure it goes through. |
| 16326 | HttpRequestInfo request; |
| 16327 | request.method = "GET"; |
| 16328 | request.url = GURL("http://www.example.org/"); |
| 16329 | |
| 16330 | MockWrite data_writes[] = { |
| 16331 | MockWrite("GET / HTTP/1.1\r\n" |
| 16332 | "Host: www.example.org\r\n" |
| 16333 | "Connection: keep-alive\r\n\r\n"), |
| 16334 | }; |
| 16335 | MockRead data_reads[] = { |
| 16336 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16337 | MockRead(SYNCHRONOUS, OK), |
| 16338 | }; |
| 16339 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16340 | arraysize(data_writes)); |
| 16341 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16342 | |
| 16343 | throttler->set_throttle_new_requests(true); |
| 16344 | std::unique_ptr<HttpTransaction> trans( |
| 16345 | new HttpNetworkTransaction(IDLE, session.get())); |
| 16346 | // Start the transaction to associate a throttle with it. |
| 16347 | TestCompletionCallback callback; |
| 16348 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16350 | |
| 16351 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16352 | trans->SetPriority(LOW); |
| 16353 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16354 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16355 | |
| 16356 | throttler->UnthrottleAllRequests(); |
| 16357 | base::RunLoop().RunUntilIdle(); |
| 16358 | ASSERT_TRUE(callback.have_result()); |
| 16359 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16360 | } |
| 16361 | |
| 16362 | // Confirm that unthrottling from a SetPriority call by the |
| 16363 | // throttler works properly. |
| 16364 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16365 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16366 | std::unique_ptr<HttpNetworkSession> session( |
| 16367 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16368 | |
| 16369 | // Send a simple request and make sure it goes through. |
| 16370 | HttpRequestInfo request; |
| 16371 | request.method = "GET"; |
| 16372 | request.url = GURL("http://www.example.org/"); |
| 16373 | |
| 16374 | MockWrite data_writes[] = { |
| 16375 | MockWrite("GET / HTTP/1.1\r\n" |
| 16376 | "Host: www.example.org\r\n" |
| 16377 | "Connection: keep-alive\r\n\r\n"), |
| 16378 | }; |
| 16379 | MockRead data_reads[] = { |
| 16380 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16381 | MockRead(SYNCHRONOUS, OK), |
| 16382 | }; |
| 16383 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16384 | arraysize(data_writes)); |
| 16385 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16386 | |
| 16387 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16388 | data_writes, arraysize(data_writes)); |
| 16389 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16390 | |
| 16391 | // Start a request that will be throttled at start; confirm it |
| 16392 | // doesn't complete. |
| 16393 | throttler->set_throttle_new_requests(true); |
| 16394 | std::unique_ptr<HttpTransaction> trans( |
| 16395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16396 | |
| 16397 | TestCompletionCallback callback; |
| 16398 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16399 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16400 | |
| 16401 | base::RunLoop().RunUntilIdle(); |
| 16402 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16403 | EXPECT_FALSE(callback.have_result()); |
| 16404 | |
| 16405 | // Create a new request, call SetPriority on it to unthrottle, |
| 16406 | // and make sure that allows the original request to complete. |
| 16407 | std::unique_ptr<HttpTransaction> trans1( |
| 16408 | new HttpNetworkTransaction(LOW, session.get())); |
| 16409 | throttler->set_priority_change_closure( |
| 16410 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16411 | base::Unretained(throttler))); |
| 16412 | |
| 16413 | // Start the transaction to associate a throttle with it. |
| 16414 | TestCompletionCallback callback1; |
| 16415 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16416 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16417 | |
| 16418 | trans1->SetPriority(IDLE); |
| 16419 | |
| 16420 | base::RunLoop().RunUntilIdle(); |
| 16421 | ASSERT_TRUE(callback.have_result()); |
| 16422 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16423 | ASSERT_TRUE(callback1.have_result()); |
| 16424 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16425 | } |
| 16426 | |
| 16427 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
| 16428 | void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {} |
| 16429 | |
| 16430 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16431 | // throttler works properly. |
| 16432 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16433 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16434 | std::unique_ptr<HttpNetworkSession> session( |
| 16435 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16436 | |
| 16437 | // Send a simple request and make sure it goes through. |
| 16438 | HttpRequestInfo request; |
| 16439 | request.method = "GET"; |
| 16440 | request.url = GURL("http://www.example.org/"); |
| 16441 | |
| 16442 | MockWrite data_writes[] = { |
| 16443 | MockWrite("GET / HTTP/1.1\r\n" |
| 16444 | "Host: www.example.org\r\n" |
| 16445 | "Connection: keep-alive\r\n\r\n"), |
| 16446 | }; |
| 16447 | MockRead data_reads[] = { |
| 16448 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16449 | MockRead(SYNCHRONOUS, OK), |
| 16450 | }; |
| 16451 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16452 | arraysize(data_writes)); |
| 16453 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16454 | |
| 16455 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16456 | data_writes, arraysize(data_writes)); |
| 16457 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16458 | |
| 16459 | // Start a request that will be throttled at start; confirm it |
| 16460 | // doesn't complete. |
| 16461 | throttler->set_throttle_new_requests(true); |
| 16462 | std::unique_ptr<HttpTransaction> trans( |
| 16463 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16464 | |
| 16465 | TestCompletionCallback callback; |
| 16466 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16468 | |
| 16469 | base::RunLoop().RunUntilIdle(); |
| 16470 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16471 | EXPECT_FALSE(callback.have_result()); |
| 16472 | |
| 16473 | // Arrange for the set priority call on the above transaction to delete |
| 16474 | // the transaction. |
| 16475 | HttpTransaction* trans_ptr(trans.get()); |
| 16476 | throttler->set_priority_change_closure( |
| 16477 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16478 | |
| 16479 | // Call it and check results (partially a "doesn't crash" test). |
| 16480 | trans_ptr->SetPriority(IDLE); |
| 16481 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16482 | |
| 16483 | base::RunLoop().RunUntilIdle(); |
| 16484 | ASSERT_FALSE(callback.have_result()); |
| 16485 | } |
| 16486 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16487 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16488 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 16489 | // Required by ChannelIDService. |
| 16490 | base::test::ScopedTaskScheduler scoped_task_scheduler( |
| 16491 | base::MessageLoop::current()); |
| 16492 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16493 | const std::string https_url = "https://www.example.com"; |
| 16494 | HttpRequestInfo request; |
| 16495 | request.url = GURL(https_url); |
| 16496 | request.method = "GET"; |
| 16497 | |
| 16498 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16499 | ssl.token_binding_negotiated = true; |
| 16500 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16501 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16503 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16504 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16505 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16506 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16507 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16508 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16509 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 16510 | session_deps_.channel_id_service.reset( |
| 16511 | new ChannelIDService(new DefaultChannelIDStore(nullptr))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16513 | |
| 16514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16515 | TestCompletionCallback callback; |
| 16516 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16517 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16518 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16519 | |
| 16520 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16521 | HttpRequestHeaders headers; |
| 16522 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16523 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16524 | } |
| 16525 | #endif // !defined(OS_IOS) |
| 16526 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16527 | } // namespace net |