[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12 | #include <memory> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 13 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 14 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 16 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 17 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 23 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 24 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 25 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 45 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 46 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 47 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 48 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 52 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 56 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 57 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 58 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 59 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 61 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 62 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 70 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 71 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 72 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 73 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 74 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 75 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 79 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 80 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 82 | #include "net/socket/socket_test_util.h" |
| 83 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 84 | #include "net/spdy/spdy_framer.h" |
| 85 | #include "net/spdy/spdy_session.h" |
| 86 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 87 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 88 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 89 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 90 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_config_service_defaults.h" |
| 92 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 93 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 94 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 95 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 96 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 97 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 98 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 99 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 100 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 101 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 103 | using net::test::IsError; |
| 104 | using net::test::IsOk; |
| 105 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 106 | using base::ASCIIToUTF16; |
| 107 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 108 | //----------------------------------------------------------------------------- |
| 109 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 110 | namespace net { |
| 111 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 112 | namespace { |
| 113 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 114 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 115 | public: |
| 116 | TestNetworkStreamThrottler() |
| 117 | : throttle_new_requests_(false), |
| 118 | num_set_priority_calls_(0), |
| 119 | last_priority_set_(IDLE) {} |
| 120 | |
| 121 | ~TestNetworkStreamThrottler() override { |
| 122 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 123 | } |
| 124 | |
| 125 | // NetworkThrottleManager |
| 126 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 127 | RequestPriority priority, |
| 128 | bool ignore_limits) override { |
| 129 | std::unique_ptr<TestThrottle> test_throttle( |
| 130 | new TestThrottle(throttle_new_requests_, delegate, this)); |
| 131 | outstanding_throttles_.insert(test_throttle.get()); |
| 132 | return std::move(test_throttle); |
| 133 | } |
| 134 | |
| 135 | void UnthrottleAllRequests() { |
| 136 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
| 137 | for (auto& throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 138 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 139 | throttle->Unthrottle(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 144 | throttle_new_requests_ = throttle_new_requests; |
| 145 | } |
| 146 | |
| 147 | // Includes both throttled and unthrottled throttles. |
| 148 | size_t num_outstanding_requests() const { |
| 149 | return outstanding_throttles_.size(); |
| 150 | } |
| 151 | |
| 152 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 153 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 154 | void set_priority_change_closure( |
| 155 | const base::Closure& priority_change_closure) { |
| 156 | priority_change_closure_ = priority_change_closure; |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 161 | public: |
| 162 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 163 | |
| 164 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 165 | bool IsBlocked() const override { return throttled_; } |
| 166 | RequestPriority Priority() const override { |
| 167 | NOTREACHED(); |
| 168 | return IDLE; |
| 169 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 170 | void SetPriority(RequestPriority priority) override { |
| 171 | throttler_->SetPriorityCalled(priority); |
| 172 | } |
| 173 | |
| 174 | TestThrottle(bool throttled, |
| 175 | ThrottleDelegate* delegate, |
| 176 | TestNetworkStreamThrottler* throttler) |
| 177 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 178 | |
| 179 | void Unthrottle() { |
| 180 | EXPECT_TRUE(throttled_); |
| 181 | |
| 182 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 183 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bool throttled_; |
| 187 | ThrottleDelegate* delegate_; |
| 188 | TestNetworkStreamThrottler* throttler_; |
| 189 | }; |
| 190 | |
| 191 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 192 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 193 | outstanding_throttles_.erase(throttle); |
| 194 | } |
| 195 | |
| 196 | void SetPriorityCalled(RequestPriority priority) { |
| 197 | ++num_set_priority_calls_; |
| 198 | last_priority_set_ = priority; |
| 199 | if (!priority_change_closure_.is_null()) |
| 200 | priority_change_closure_.Run(); |
| 201 | } |
| 202 | |
| 203 | // Includes both throttled and unthrottled throttles. |
| 204 | std::set<TestThrottle*> outstanding_throttles_; |
| 205 | bool throttle_new_requests_; |
| 206 | int num_set_priority_calls_; |
| 207 | RequestPriority last_priority_set_; |
| 208 | base::Closure priority_change_closure_; |
| 209 | |
| 210 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 211 | }; |
| 212 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 213 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 214 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 215 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 216 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 217 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 218 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 219 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 220 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 221 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 222 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 223 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 224 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 225 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 226 | const char kAlternativeServiceHttpHeader[] = |
| 227 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 228 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 229 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 230 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 231 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 232 | } |
| 233 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 234 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 235 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 236 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 237 | } |
| 238 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 239 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 240 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 241 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 244 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 245 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 246 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 247 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 248 | if (!params) |
| 249 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 250 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 251 | if (!params->GetList("headers", &header_list)) |
| 252 | return false; |
| 253 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 254 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 255 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 256 | return true; |
| 257 | } |
| 258 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 259 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 260 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 261 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 262 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 263 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 264 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 265 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 266 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 267 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 268 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 270 | |
| 271 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 272 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 273 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 275 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 276 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 279 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 280 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 281 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 283 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 284 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 285 | |
| 286 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 287 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 288 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 289 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 290 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 291 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 292 | load_timing_info.send_start); |
| 293 | |
| 294 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 295 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 296 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 297 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 298 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 299 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 303 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 304 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 305 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 306 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 308 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 309 | |
| 310 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 311 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 312 | load_timing_info.proxy_resolve_end); |
| 313 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 314 | load_timing_info.send_start); |
| 315 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 316 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 317 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 318 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 319 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 320 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 324 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 325 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 326 | int connect_timing_flags) { |
| 327 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 328 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 329 | |
| 330 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 331 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 332 | load_timing_info.proxy_resolve_end); |
| 333 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 334 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 335 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 336 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 337 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 338 | load_timing_info.send_start); |
| 339 | |
| 340 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 341 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 342 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 343 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 344 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 345 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 346 | } |
| 347 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 348 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 349 | headers->SetHeader("Connection", "Upgrade"); |
| 350 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 351 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 352 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 353 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 354 | } |
| 355 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 356 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 357 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 358 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 359 | } |
| 360 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 361 | // Note that the pointer written into |*throttler| will only be valid |
| 362 | // for the lifetime of the returned HttpNetworkSession. |
| 363 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 364 | SpdySessionDependencies* session_deps, |
| 365 | TestNetworkStreamThrottler** throttler) { |
| 366 | std::unique_ptr<HttpNetworkSession> session( |
| 367 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 368 | |
| 369 | std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( |
| 370 | new TestNetworkStreamThrottler); |
| 371 | *throttler = owned_throttler.get(); |
| 372 | |
| 373 | HttpNetworkSessionPeer peer(session.get()); |
| 374 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 375 | |
| 376 | return session; |
| 377 | } |
| 378 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 379 | } // namespace |
| 380 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 381 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 382 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 383 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 384 | // Important to restore the per-pool limit first, since the pool limit must |
| 385 | // always be greater than group limit, and the tests reduce both limits. |
| 386 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 387 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 388 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 389 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 390 | } |
| 391 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 392 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 393 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 394 | : ssl_(ASYNC, OK), |
| 395 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 396 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 397 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 398 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 399 | session_deps_.enable_http2_alternative_service_with_different_host = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 400 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 401 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 402 | struct SimpleGetHelperResult { |
| 403 | int rv; |
| 404 | std::string status_line; |
| 405 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 406 | int64_t total_received_bytes; |
| 407 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 408 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 409 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 410 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 411 | }; |
| 412 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 413 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 414 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 415 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 416 | } |
| 417 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 418 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 419 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 420 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 421 | // Empty the current queue. |
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 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 424 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 428 | // Either |write_failure| specifies a write failure or |read_failure| |
| 429 | // specifies a read failure when using a reused socket. In either case, the |
| 430 | // failure should cause the network transaction to resend the request, and the |
| 431 | // other argument should be NULL. |
| 432 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 433 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 434 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 435 | // Either |write_failure| specifies a write failure or |read_failure| |
| 436 | // specifies a read failure when using a reused socket. In either case, the |
| 437 | // failure should cause the network transaction to resend the request, and the |
| 438 | // other argument should be NULL. |
| 439 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 440 | const MockRead* read_failure, |
| 441 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 442 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 443 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 444 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 445 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 446 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | HttpRequestInfo request; |
| 448 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 449 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 450 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 451 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 452 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 455 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 456 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 457 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 458 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 460 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 462 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 463 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 465 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 466 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 468 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 469 | |
| 470 | // Even in the failure cases that use this function, connections are always |
| 471 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 472 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 473 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 474 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 475 | if (out.rv != OK) |
| 476 | return out; |
| 477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 479 | // Can't use ASSERT_* inside helper functions like this, so |
| 480 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 481 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 482 | out.rv = ERR_UNEXPECTED; |
| 483 | return out; |
| 484 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 485 | out.status_line = response->headers->GetStatusLine(); |
| 486 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 487 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 488 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 489 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 490 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 491 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 492 | EXPECT_EQ(got_endpoint, |
| 493 | out.remote_endpoint_after_start.address().size() > 0); |
| 494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 495 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 497 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 498 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 499 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 500 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 501 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 502 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 503 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 504 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 505 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 506 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 507 | std::string line; |
| 508 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 509 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 510 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 511 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 513 | std::string value; |
| 514 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 515 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 516 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 517 | EXPECT_EQ("keep-alive", value); |
| 518 | |
| 519 | std::string response_headers; |
| 520 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 521 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 522 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 524 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 525 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 526 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 528 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 529 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 530 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 531 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 532 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 533 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | MockWrite data_writes[] = { |
| 535 | MockWrite("GET / HTTP/1.1\r\n" |
| 536 | "Host: www.example.org\r\n" |
| 537 | "Connection: keep-alive\r\n\r\n"), |
| 538 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 539 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 540 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 541 | arraysize(data_writes)); |
| 542 | StaticSocketDataProvider* data[] = {&reads}; |
| 543 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 544 | |
| 545 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 546 | out.total_sent_bytes); |
| 547 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 548 | } |
| 549 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 550 | void AddSSLSocketData() { |
| 551 | ssl_.next_proto = kProtoHTTP2; |
| 552 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 553 | ASSERT_TRUE(ssl_.cert); |
| 554 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 555 | } |
| 556 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 557 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 558 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 559 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 560 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 561 | |
| 562 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 563 | |
| 564 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 565 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 566 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 567 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 568 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 569 | |
| 570 | // Original socket limits. Some tests set these. Safest to always restore |
| 571 | // them once each test has been run. |
| 572 | int old_max_group_sockets_; |
| 573 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 574 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 575 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 576 | namespace { |
| 577 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 578 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 579 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 580 | BeforeHeadersSentHandler() |
| 581 | : observed_before_headers_sent_with_proxy_(false), |
| 582 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 583 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 584 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 585 | HttpRequestHeaders* request_headers) { |
| 586 | observed_before_headers_sent_ = true; |
| 587 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 588 | !proxy_info.is_quic()) { |
| 589 | return; |
| 590 | } |
| 591 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 592 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 593 | } |
| 594 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 595 | bool observed_before_headers_sent_with_proxy() const { |
| 596 | return observed_before_headers_sent_with_proxy_; |
| 597 | } |
| 598 | |
| 599 | bool observed_before_headers_sent() const { |
| 600 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | std::string observed_proxy_server_uri() const { |
| 604 | return observed_proxy_server_uri_; |
| 605 | } |
| 606 | |
| 607 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 608 | bool observed_before_headers_sent_with_proxy_; |
| 609 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 610 | std::string observed_proxy_server_uri_; |
| 611 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 612 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 613 | }; |
| 614 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 615 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 616 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 617 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 618 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 619 | const int sizeof_row = strlen(row); |
| 620 | const int num_rows = static_cast<int>( |
| 621 | ceil(static_cast<float>(size) / sizeof_row)); |
| 622 | const int sizeof_data = num_rows * sizeof_row; |
| 623 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 624 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 625 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 626 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 627 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 628 | } |
| 629 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 630 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 631 | // Alternative functions that eliminate randomness and dependency on the local |
| 632 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 633 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 634 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 635 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | static size_t current_byte = 0; |
| 637 | for (size_t i = 0; i < n; ++i) { |
| 638 | output[i] = bytes[current_byte++]; |
| 639 | current_byte %= arraysize(bytes); |
| 640 | } |
| 641 | } |
| 642 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 643 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 644 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 645 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 646 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 647 | static size_t current_byte = 0; |
| 648 | for (size_t i = 0; i < n; ++i) { |
| 649 | output[i] = bytes[current_byte++]; |
| 650 | current_byte %= arraysize(bytes); |
| 651 | } |
| 652 | } |
| 653 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 654 | std::string MockGetHostName() { |
| 655 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 656 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 657 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 658 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 659 | template<typename ParentPool> |
| 660 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 661 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 662 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 663 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 664 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 665 | const std::string last_group_name_received() const { |
| 666 | return last_group_name_; |
| 667 | } |
| 668 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 669 | int RequestSocket(const std::string& group_name, |
| 670 | const void* socket_params, |
| 671 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 672 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 673 | ClientSocketHandle* handle, |
| 674 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 675 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 676 | last_group_name_ = group_name; |
| 677 | return ERR_IO_PENDING; |
| 678 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | void CancelRequest(const std::string& group_name, |
| 680 | ClientSocketHandle* handle) override {} |
| 681 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 682 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 683 | int id) override {} |
| 684 | void CloseIdleSockets() override {} |
| 685 | int IdleSocketCount() const override { return 0; } |
| 686 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 687 | return 0; |
| 688 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | LoadState GetLoadState(const std::string& group_name, |
| 690 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 691 | return LOAD_STATE_IDLE; |
| 692 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 693 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 694 | return base::TimeDelta(); |
| 695 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 696 | |
| 697 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 698 | std::string last_group_name_; |
| 699 | }; |
| 700 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 701 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 702 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 703 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 704 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 705 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 706 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 707 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 708 | CaptureGroupNameSSLSocketPool; |
| 709 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 710 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 711 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 712 | HostResolver* host_resolver, |
| 713 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 714 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 715 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 716 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 717 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 718 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 719 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 720 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 721 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 722 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 723 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 724 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 725 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 726 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 727 | : SSLClientSocketPool(0, |
| 728 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 729 | cert_verifier, |
| 730 | NULL, |
| 731 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 732 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 733 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 734 | std::string(), |
| 735 | NULL, |
| 736 | NULL, |
| 737 | NULL, |
| 738 | NULL, |
| 739 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 740 | NULL) { |
| 741 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 742 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 743 | //----------------------------------------------------------------------------- |
| 744 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 745 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 746 | // configured for common cases. |
| 747 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 748 | if (!auth_challenge) |
| 749 | return false; |
| 750 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 751 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 753 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | return true; |
| 755 | } |
| 756 | |
| 757 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 758 | if (!auth_challenge) |
| 759 | return false; |
| 760 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 761 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 762 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 763 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 764 | return true; |
| 765 | } |
| 766 | |
| 767 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 768 | if (!auth_challenge) |
| 769 | return false; |
| 770 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 771 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 772 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 773 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 774 | return true; |
| 775 | } |
| 776 | |
| 777 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 778 | if (!auth_challenge) |
| 779 | return false; |
| 780 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 781 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 782 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 783 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | return true; |
| 785 | } |
| 786 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 787 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 788 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 789 | if (!auth_challenge) |
| 790 | return false; |
| 791 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 792 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 793 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 794 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 795 | return true; |
| 796 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 797 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 798 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 799 | } // namespace |
| 800 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 801 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | } |
| 805 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 806 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 808 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 809 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 810 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 811 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 812 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 813 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 814 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 815 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 816 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 817 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 818 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 819 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 820 | |
| 821 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 825 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 826 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 827 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 829 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 830 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 831 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 832 | EXPECT_THAT(out.rv, IsOk()); |
| 833 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 834 | EXPECT_EQ("hello world", out.response_data); |
| 835 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 836 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 837 | } |
| 838 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 839 | // Response with no status line, and a weird port. Should fail by default. |
| 840 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 841 | MockRead data_reads[] = { |
| 842 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 843 | }; |
| 844 | |
| 845 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 847 | |
| 848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 849 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 850 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 851 | std::unique_ptr<HttpTransaction> trans( |
| 852 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 853 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 854 | request.method = "GET"; |
| 855 | request.url = GURL("http://www.example.com:2000/"); |
| 856 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 857 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 858 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 859 | } |
| 860 | |
| 861 | // Response with no status line, and a weird port. Option to allow weird ports |
| 862 | // enabled. |
| 863 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 864 | MockRead data_reads[] = { |
| 865 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 866 | }; |
| 867 | |
| 868 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 869 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 870 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 871 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 872 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 873 | HttpRequestInfo request; |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 874 | std::unique_ptr<HttpTransaction> trans( |
| 875 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 876 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 877 | request.method = "GET"; |
| 878 | request.url = GURL("http://www.example.com:2000/"); |
| 879 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 880 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 881 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 882 | |
| 883 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 884 | ASSERT_TRUE(info->headers); |
| 885 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 886 | |
| 887 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 888 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 889 | } |
| 890 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 891 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 892 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 893 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 894 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 895 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 896 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 897 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 898 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 899 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 900 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 901 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 902 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 903 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 907 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 908 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 909 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 914 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 915 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 916 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 917 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 918 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 922 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 923 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 924 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 927 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 928 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 929 | EXPECT_THAT(out.rv, IsOk()); |
| 930 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 931 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 932 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 933 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 937 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 939 | MockRead("\n"), |
| 940 | MockRead("\n"), |
| 941 | MockRead("Q"), |
| 942 | MockRead("J"), |
| 943 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 945 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 946 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 947 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 948 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 950 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 951 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 952 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 956 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 957 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 958 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 959 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 961 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 962 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 963 | EXPECT_THAT(out.rv, IsOk()); |
| 964 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 965 | EXPECT_EQ("HTT", out.response_data); |
| 966 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 967 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 970 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 971 | // persistent connection. The response should still terminate since a 204 |
| 972 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 973 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 974 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 975 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 976 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 977 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 978 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 979 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 980 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 981 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 982 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 983 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 984 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 985 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 986 | int64_t response_size = reads_size - strlen(junk); |
| 987 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 988 | } |
| 989 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 990 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 991 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 992 | std::string final_chunk = "0\r\n\r\n"; |
| 993 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 994 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 995 | MockRead data_reads[] = { |
| 996 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 997 | MockRead("5\r\nHello\r\n"), |
| 998 | MockRead("1\r\n"), |
| 999 | MockRead(" \r\n"), |
| 1000 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1001 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1002 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1003 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1004 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1005 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1006 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1007 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1008 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1009 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1010 | int64_t response_size = reads_size - extra_data.size(); |
| 1011 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1012 | } |
| 1013 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1014 | // Next tests deal with http://crbug.com/56344. |
| 1015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1016 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1017 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1018 | MockRead data_reads[] = { |
| 1019 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1020 | MockRead("Content-Length: 10\r\n"), |
| 1021 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1022 | }; |
| 1023 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1024 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1025 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1026 | } |
| 1027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1028 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1029 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1030 | MockRead data_reads[] = { |
| 1031 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1032 | MockRead("Content-Length: 5\r\n"), |
| 1033 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1034 | MockRead("Hello"), |
| 1035 | }; |
| 1036 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1037 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1038 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1039 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1040 | EXPECT_EQ("Hello", out.response_data); |
| 1041 | } |
| 1042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1043 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1044 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1045 | // More than 2 dupes. |
| 1046 | { |
| 1047 | MockRead data_reads[] = { |
| 1048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1049 | MockRead("Content-Length: 5\r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n"), |
| 1051 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1052 | MockRead("Hello"), |
| 1053 | }; |
| 1054 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1055 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1056 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1057 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1058 | EXPECT_EQ("Hello", out.response_data); |
| 1059 | } |
| 1060 | // HTTP/1.0 |
| 1061 | { |
| 1062 | MockRead data_reads[] = { |
| 1063 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1064 | MockRead("Content-Length: 5\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1067 | MockRead("Hello"), |
| 1068 | }; |
| 1069 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1070 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1071 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1072 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1073 | EXPECT_EQ("Hello", out.response_data); |
| 1074 | } |
| 1075 | // 2 dupes and one mismatched. |
| 1076 | { |
| 1077 | MockRead data_reads[] = { |
| 1078 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1079 | MockRead("Content-Length: 10\r\n"), |
| 1080 | MockRead("Content-Length: 10\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1082 | }; |
| 1083 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1084 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1085 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1089 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1090 | MultipleContentLengthHeadersTransferEncoding) { |
| 1091 | MockRead data_reads[] = { |
| 1092 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1093 | MockRead("Content-Length: 666\r\n"), |
| 1094 | MockRead("Content-Length: 1337\r\n"), |
| 1095 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1096 | MockRead("5\r\nHello\r\n"), |
| 1097 | MockRead("1\r\n"), |
| 1098 | MockRead(" \r\n"), |
| 1099 | MockRead("5\r\nworld\r\n"), |
| 1100 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1101 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1102 | }; |
| 1103 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1104 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1105 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1106 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1107 | EXPECT_EQ("Hello world", out.response_data); |
| 1108 | } |
| 1109 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | // Next tests deal with http://crbug.com/98895. |
| 1111 | |
| 1112 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1113 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1114 | MockRead data_reads[] = { |
| 1115 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1116 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1117 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1118 | MockRead("Hello"), |
| 1119 | }; |
| 1120 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1121 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1122 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1123 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1124 | EXPECT_EQ("Hello", out.response_data); |
| 1125 | } |
| 1126 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1127 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1128 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1129 | MockRead data_reads[] = { |
| 1130 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1131 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1132 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1133 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1134 | MockRead("Hello"), |
| 1135 | }; |
| 1136 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1137 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1138 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1139 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1140 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1144 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1145 | MockRead data_reads[] = { |
| 1146 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1147 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1148 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1149 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1150 | MockRead("Hello"), |
| 1151 | }; |
| 1152 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1153 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1154 | EXPECT_THAT(out.rv, |
| 1155 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1156 | } |
| 1157 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1158 | // Checks that two identical Location headers result in no error. |
| 1159 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1160 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | MockRead data_reads[] = { |
| 1162 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1163 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1164 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1165 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1166 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | }; |
| 1168 | |
| 1169 | HttpRequestInfo request; |
| 1170 | request.method = "GET"; |
| 1171 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1174 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | |
| 1176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1179 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1180 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1181 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1184 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1186 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1187 | ASSERT_TRUE(response); |
| 1188 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1189 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1190 | std::string url; |
| 1191 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1192 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1193 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1197 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1198 | MockRead data_reads[] = { |
| 1199 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1200 | MockRead("Location: http://good.com/\r\n"), |
| 1201 | MockRead("Location: http://evil.com/\r\n"), |
| 1202 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1203 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1204 | }; |
| 1205 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1206 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1207 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | } |
| 1209 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1210 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1211 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1212 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1213 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1214 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1215 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1218 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1219 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1220 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1221 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1222 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1223 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1225 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1226 | "Host: www.example.org\r\n" |
| 1227 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | }; |
| 1229 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1230 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1231 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1233 | // No response body because the test stops reading here. |
| 1234 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1235 | }; |
| 1236 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1237 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1238 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1239 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1241 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1243 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
| 1246 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1247 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1249 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1250 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
| 1252 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1253 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1255 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1256 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1257 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1258 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1259 | |
| 1260 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1261 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | bool has_server_header = response->headers->EnumerateHeader( |
| 1263 | &iter, "Server", &server_header); |
| 1264 | EXPECT_TRUE(has_server_header); |
| 1265 | EXPECT_EQ("Blah", server_header); |
| 1266 | |
| 1267 | // Reading should give EOF right away, since there is no message body |
| 1268 | // (despite non-zero content-length). |
| 1269 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1270 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1271 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1272 | EXPECT_EQ("", response_data); |
| 1273 | } |
| 1274 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1275 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1277 | |
| 1278 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1279 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1280 | MockRead("hello"), |
| 1281 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1282 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1283 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1287 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1288 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | "hello", "world" |
| 1290 | }; |
| 1291 | |
| 1292 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1293 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1295 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1299 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1301 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1302 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
| 1304 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1305 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1307 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1308 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1310 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1311 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1312 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | |
| 1314 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1315 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1316 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1317 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1321 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1322 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1323 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1324 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1325 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1326 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1327 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | request.method = "POST"; |
| 1329 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1330 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1332 | // Check the upload progress returned before initialization is correct. |
| 1333 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1334 | EXPECT_EQ(0u, progress.size()); |
| 1335 | EXPECT_EQ(0u, progress.position()); |
| 1336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1339 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1341 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1342 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1343 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1344 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1346 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1349 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1351 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1352 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
| 1354 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1355 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1357 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1358 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1360 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1361 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
| 1363 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1364 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1365 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1366 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | } |
| 1368 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1369 | // This test is almost the same as Ignores100 above, but the response contains |
| 1370 | // 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] | 1371 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1372 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1373 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1374 | request.method = "GET"; |
| 1375 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1376 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1379 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1380 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1381 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1382 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1383 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1386 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1389 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1391 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | |
| 1394 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1395 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1397 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1398 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1399 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1400 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1402 | |
| 1403 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1404 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | EXPECT_EQ("hello world", response_data); |
| 1407 | } |
| 1408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1409 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1410 | HttpRequestInfo request; |
| 1411 | request.method = "POST"; |
| 1412 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1413 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1414 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1415 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1416 | |
| 1417 | MockRead data_reads[] = { |
| 1418 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1419 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1420 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1421 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1423 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1424 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1426 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1428 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1429 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1431 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1432 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1433 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1434 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1435 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1436 | } |
| 1437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1438 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1439 | HttpRequestInfo request; |
| 1440 | request.method = "POST"; |
| 1441 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1445 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1446 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1447 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1448 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1449 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1450 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1452 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1453 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1454 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1456 | |
| 1457 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1458 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1459 | } |
| 1460 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1461 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1462 | const MockWrite* write_failure, |
| 1463 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1464 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1465 | request.method = "GET"; |
| 1466 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1467 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1468 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1469 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1471 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1472 | // Written data for successfully sending both requests. |
| 1473 | MockWrite data1_writes[] = { |
| 1474 | MockWrite("GET / HTTP/1.1\r\n" |
| 1475 | "Host: www.foo.com\r\n" |
| 1476 | "Connection: keep-alive\r\n\r\n"), |
| 1477 | MockWrite("GET / HTTP/1.1\r\n" |
| 1478 | "Host: www.foo.com\r\n" |
| 1479 | "Connection: keep-alive\r\n\r\n") |
| 1480 | }; |
| 1481 | |
| 1482 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1484 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1485 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1486 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1487 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1488 | |
| 1489 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1490 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1491 | data1_writes[1] = *write_failure; |
| 1492 | } else { |
| 1493 | ASSERT_TRUE(read_failure); |
| 1494 | data1_reads[2] = *read_failure; |
| 1495 | } |
| 1496 | |
| 1497 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1498 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1499 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1500 | |
| 1501 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1502 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1503 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1504 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1505 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1506 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1507 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1508 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1509 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1510 | "hello", "world" |
| 1511 | }; |
| 1512 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1513 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1514 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1515 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1518 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1519 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1521 | |
| 1522 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1523 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1524 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1525 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1526 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1527 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1528 | if (i == 0) { |
| 1529 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1530 | } else { |
| 1531 | // The second request should be using a new socket. |
| 1532 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1533 | } |
| 1534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1535 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1536 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1537 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1538 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1539 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1540 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1541 | |
| 1542 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1543 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1545 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1546 | } |
| 1547 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1548 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1549 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1550 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1551 | const MockRead* read_failure, |
| 1552 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1553 | HttpRequestInfo request; |
| 1554 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1555 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1557 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1558 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1560 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1561 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1562 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1563 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1564 | ssl1.next_proto = kProtoHTTP2; |
| 1565 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1566 | } |
| 1567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1569 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1570 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1571 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1572 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1573 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1574 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1575 | SpdySerializedFrame spdy_data( |
| 1576 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1577 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1578 | // HTTP/1.1 versions of the request and response. |
| 1579 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1580 | "Host: www.foo.com\r\n" |
| 1581 | "Connection: keep-alive\r\n\r\n"; |
| 1582 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1583 | const char kHttpData[] = "hello"; |
| 1584 | |
| 1585 | std::vector<MockRead> data1_reads; |
| 1586 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | if (write_failure) { |
| 1588 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1589 | data1_writes.push_back(*write_failure); |
| 1590 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1591 | } else { |
| 1592 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1593 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1594 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1595 | } else { |
| 1596 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1597 | } |
| 1598 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1599 | } |
| 1600 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1601 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1602 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1603 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1604 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1605 | std::vector<MockRead> data2_reads; |
| 1606 | std::vector<MockWrite> data2_writes; |
| 1607 | |
| 1608 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1609 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1610 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1611 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1612 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1613 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1614 | } else { |
| 1615 | data2_writes.push_back( |
| 1616 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1617 | |
| 1618 | data2_reads.push_back( |
| 1619 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1620 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1621 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1622 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1623 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1624 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1625 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1626 | |
| 1627 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1628 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1629 | // Wait for the preconnect to complete. |
| 1630 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1631 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1632 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1633 | |
| 1634 | // Make the request. |
| 1635 | TestCompletionCallback callback; |
| 1636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1641 | |
| 1642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1644 | |
| 1645 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1646 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1647 | TestLoadTimingNotReused( |
| 1648 | load_timing_info, |
| 1649 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1652 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1653 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1654 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1655 | if (response->was_fetched_via_spdy) { |
| 1656 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1657 | } else { |
| 1658 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1659 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1660 | |
| 1661 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1662 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1663 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1664 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1665 | } |
| 1666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1667 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1668 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1669 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1670 | } |
| 1671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1672 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1673 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1674 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1675 | } |
| 1676 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1677 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1678 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1679 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1680 | } |
| 1681 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1682 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1683 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1684 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1685 | MockRead read_failure(SYNCHRONOUS, |
| 1686 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1687 | "Connection: Keep-Alive\r\n" |
| 1688 | "Content-Length: 6\r\n\r\n" |
| 1689 | "Pickle"); |
| 1690 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1691 | } |
| 1692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1693 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1694 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1695 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1696 | } |
| 1697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1698 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1699 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1700 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1701 | } |
| 1702 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1703 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1704 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1705 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1706 | } |
| 1707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1708 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1709 | MockRead read_failure(ASYNC, OK); // EOF |
| 1710 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1711 | } |
| 1712 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1713 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1714 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1715 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1716 | MockRead read_failure(SYNCHRONOUS, |
| 1717 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1718 | "Connection: Keep-Alive\r\n" |
| 1719 | "Content-Length: 6\r\n\r\n" |
| 1720 | "Pickle"); |
| 1721 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1722 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1723 | } |
| 1724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1725 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1726 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1727 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1728 | } |
| 1729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1730 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1731 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1732 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1733 | } |
| 1734 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1735 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1736 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1737 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1738 | } |
| 1739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1740 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1741 | MockRead read_failure(ASYNC, OK); // EOF |
| 1742 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1743 | } |
| 1744 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1745 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1746 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1747 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1748 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1749 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1750 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1751 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1752 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1753 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1754 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1755 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1756 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1758 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1760 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1762 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1763 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1764 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1765 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1766 | |
| 1767 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1768 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1769 | |
| 1770 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1771 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1772 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | // What do various browsers do when the server closes a non-keepalive |
| 1776 | // connection without sending any response header or body? |
| 1777 | // |
| 1778 | // IE7: error page |
| 1779 | // Safari 3.1.2 (Windows): error page |
| 1780 | // Firefox 3.0.1: blank page |
| 1781 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1782 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1783 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1784 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1785 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1786 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1787 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1788 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1790 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1791 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1792 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1793 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1794 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1795 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1796 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1797 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1798 | // destructor in such situations. |
| 1799 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1800 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1801 | HttpRequestInfo request; |
| 1802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1803 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1806 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1808 | |
| 1809 | MockRead data_reads[] = { |
| 1810 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1811 | MockRead("Connection: keep-alive\r\n"), |
| 1812 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1813 | MockRead("hello"), |
| 1814 | MockRead(SYNCHRONOUS, 0), |
| 1815 | }; |
| 1816 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1817 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1818 | |
| 1819 | TestCompletionCallback callback; |
| 1820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1821 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1823 | |
| 1824 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1826 | |
| 1827 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1828 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1829 | if (rv == ERR_IO_PENDING) |
| 1830 | rv = callback.WaitForResult(); |
| 1831 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1832 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1833 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1834 | |
| 1835 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1836 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1837 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1838 | } |
| 1839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1840 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1841 | HttpRequestInfo request; |
| 1842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1843 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1846 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1847 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1848 | |
| 1849 | MockRead data_reads[] = { |
| 1850 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1851 | MockRead("Connection: keep-alive\r\n"), |
| 1852 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1853 | MockRead(SYNCHRONOUS, 0), |
| 1854 | }; |
| 1855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1857 | |
| 1858 | TestCompletionCallback callback; |
| 1859 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1860 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1862 | |
| 1863 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1864 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1865 | |
| 1866 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1867 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1868 | if (rv == ERR_IO_PENDING) |
| 1869 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1870 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1871 | |
| 1872 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1873 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1874 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1875 | } |
| 1876 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1877 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1878 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1879 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1880 | HttpRequestInfo request; |
| 1881 | request.method = "GET"; |
| 1882 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1883 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1884 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1885 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1887 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1888 | const char* request_data = |
| 1889 | "GET / HTTP/1.1\r\n" |
| 1890 | "Host: www.foo.com\r\n" |
| 1891 | "Connection: keep-alive\r\n\r\n"; |
| 1892 | MockWrite data_writes[] = { |
| 1893 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1894 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1895 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1896 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1897 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1898 | }; |
| 1899 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1900 | // Note that because all these reads happen in the same |
| 1901 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1902 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1903 | MockRead data_reads[] = { |
| 1904 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1905 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1906 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1907 | MockRead(ASYNC, 7, |
| 1908 | "HTTP/1.1 302 Found\r\n" |
| 1909 | "Content-Length: 0\r\n\r\n"), |
| 1910 | MockRead(ASYNC, 9, |
| 1911 | "HTTP/1.1 302 Found\r\n" |
| 1912 | "Content-Length: 5\r\n\r\n" |
| 1913 | "hello"), |
| 1914 | MockRead(ASYNC, 11, |
| 1915 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1916 | "Content-Length: 0\r\n\r\n"), |
| 1917 | MockRead(ASYNC, 13, |
| 1918 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1919 | "Content-Length: 5\r\n\r\n" |
| 1920 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1921 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1922 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1923 | // the set_busy_before_sync_reads(true) call, while the |
| 1924 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1925 | // reuseable. See http://crbug.com/544255. |
| 1926 | MockRead(ASYNC, 15, |
| 1927 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1928 | "Content-Length: 5\r\n\r\n"), |
| 1929 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1930 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1931 | MockRead(ASYNC, 18, |
| 1932 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1933 | "Content-Length: 5\r\n\r\n" |
| 1934 | "he"), |
| 1935 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1936 | |
| 1937 | // The body of the final request is actually read. |
| 1938 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1939 | MockRead(ASYNC, 22, "hello"), |
| 1940 | }; |
| 1941 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1942 | arraysize(data_writes)); |
| 1943 | data.set_busy_before_sync_reads(true); |
| 1944 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1945 | |
| 1946 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1947 | std::string response_lines[kNumUnreadBodies]; |
| 1948 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1949 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1950 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1951 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1953 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1954 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1955 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1956 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1957 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1958 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1959 | LoadTimingInfo load_timing_info; |
| 1960 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1961 | if (i == 0) { |
| 1962 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1963 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1964 | } else { |
| 1965 | TestLoadTimingReused(load_timing_info); |
| 1966 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1967 | } |
| 1968 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1969 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1970 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1971 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1972 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1973 | response_lines[i] = response->headers->GetStatusLine(); |
| 1974 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1975 | // Delete the transaction without reading the response bodies. Then spin |
| 1976 | // the message loop, so the response bodies are drained. |
| 1977 | trans.reset(); |
| 1978 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1979 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1980 | |
| 1981 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1982 | "HTTP/1.1 204 No Content", |
| 1983 | "HTTP/1.1 205 Reset Content", |
| 1984 | "HTTP/1.1 304 Not Modified", |
| 1985 | "HTTP/1.1 302 Found", |
| 1986 | "HTTP/1.1 302 Found", |
| 1987 | "HTTP/1.1 301 Moved Permanently", |
| 1988 | "HTTP/1.1 301 Moved Permanently", |
| 1989 | "HTTP/1.1 200 Hunky-Dory", |
| 1990 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1991 | }; |
| 1992 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1993 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1994 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1995 | |
| 1996 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1997 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1999 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2001 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2002 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2003 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2004 | ASSERT_TRUE(response); |
| 2005 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2006 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2008 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2010 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2011 | } |
| 2012 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2013 | // Sockets that receive extra data after a response is complete should not be |
| 2014 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2015 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2017 | MockWrite data_writes1[] = { |
| 2018 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2019 | "Host: www.borked.com\r\n" |
| 2020 | "Connection: keep-alive\r\n\r\n"), |
| 2021 | }; |
| 2022 | |
| 2023 | MockRead data_reads1[] = { |
| 2024 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2025 | "Connection: keep-alive\r\n" |
| 2026 | "Content-Length: 22\r\n\r\n" |
| 2027 | "This server is borked."), |
| 2028 | }; |
| 2029 | |
| 2030 | MockWrite data_writes2[] = { |
| 2031 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2032 | "Host: www.borked.com\r\n" |
| 2033 | "Connection: keep-alive\r\n\r\n"), |
| 2034 | }; |
| 2035 | |
| 2036 | MockRead data_reads2[] = { |
| 2037 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2038 | "Content-Length: 3\r\n\r\n" |
| 2039 | "foo"), |
| 2040 | }; |
| 2041 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2042 | data_writes1, arraysize(data_writes1)); |
| 2043 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2044 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2045 | data_writes2, arraysize(data_writes2)); |
| 2046 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2047 | |
| 2048 | TestCompletionCallback callback; |
| 2049 | HttpRequestInfo request1; |
| 2050 | request1.method = "HEAD"; |
| 2051 | request1.url = GURL("http://www.borked.com/"); |
| 2052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2053 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2054 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2055 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2056 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2057 | |
| 2058 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2059 | ASSERT_TRUE(response1); |
| 2060 | ASSERT_TRUE(response1->headers); |
| 2061 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2062 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2063 | |
| 2064 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2065 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2066 | EXPECT_EQ("", response_data1); |
| 2067 | // Deleting the transaction attempts to release the socket back into the |
| 2068 | // socket pool. |
| 2069 | trans1.reset(); |
| 2070 | |
| 2071 | HttpRequestInfo request2; |
| 2072 | request2.method = "GET"; |
| 2073 | request2.url = GURL("http://www.borked.com/foo"); |
| 2074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2075 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2077 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2078 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2079 | |
| 2080 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2081 | ASSERT_TRUE(response2); |
| 2082 | ASSERT_TRUE(response2->headers); |
| 2083 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2084 | |
| 2085 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2086 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2087 | EXPECT_EQ("foo", response_data2); |
| 2088 | } |
| 2089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2090 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2092 | MockWrite data_writes1[] = { |
| 2093 | MockWrite("GET / HTTP/1.1\r\n" |
| 2094 | "Host: www.borked.com\r\n" |
| 2095 | "Connection: keep-alive\r\n\r\n"), |
| 2096 | }; |
| 2097 | |
| 2098 | MockRead data_reads1[] = { |
| 2099 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2100 | "Connection: keep-alive\r\n" |
| 2101 | "Content-Length: 22\r\n\r\n" |
| 2102 | "This server is borked." |
| 2103 | "Bonus data!"), |
| 2104 | }; |
| 2105 | |
| 2106 | MockWrite data_writes2[] = { |
| 2107 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2108 | "Host: www.borked.com\r\n" |
| 2109 | "Connection: keep-alive\r\n\r\n"), |
| 2110 | }; |
| 2111 | |
| 2112 | MockRead data_reads2[] = { |
| 2113 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2114 | "Content-Length: 3\r\n\r\n" |
| 2115 | "foo"), |
| 2116 | }; |
| 2117 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2118 | data_writes1, arraysize(data_writes1)); |
| 2119 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2120 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2121 | data_writes2, arraysize(data_writes2)); |
| 2122 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2123 | |
| 2124 | TestCompletionCallback callback; |
| 2125 | HttpRequestInfo request1; |
| 2126 | request1.method = "GET"; |
| 2127 | request1.url = GURL("http://www.borked.com/"); |
| 2128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2129 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2131 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2132 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2133 | |
| 2134 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2135 | ASSERT_TRUE(response1); |
| 2136 | ASSERT_TRUE(response1->headers); |
| 2137 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2138 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2139 | |
| 2140 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2141 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2142 | EXPECT_EQ("This server is borked.", response_data1); |
| 2143 | // Deleting the transaction attempts to release the socket back into the |
| 2144 | // socket pool. |
| 2145 | trans1.reset(); |
| 2146 | |
| 2147 | HttpRequestInfo request2; |
| 2148 | request2.method = "GET"; |
| 2149 | request2.url = GURL("http://www.borked.com/foo"); |
| 2150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2151 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2153 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2154 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2155 | |
| 2156 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2157 | ASSERT_TRUE(response2); |
| 2158 | ASSERT_TRUE(response2->headers); |
| 2159 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2160 | |
| 2161 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2162 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2163 | EXPECT_EQ("foo", response_data2); |
| 2164 | } |
| 2165 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2166 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2168 | MockWrite data_writes1[] = { |
| 2169 | MockWrite("GET / HTTP/1.1\r\n" |
| 2170 | "Host: www.borked.com\r\n" |
| 2171 | "Connection: keep-alive\r\n\r\n"), |
| 2172 | }; |
| 2173 | |
| 2174 | MockRead data_reads1[] = { |
| 2175 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2176 | "Connection: keep-alive\r\n" |
| 2177 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2178 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2179 | MockRead("0\r\n\r\nBonus data!"), |
| 2180 | }; |
| 2181 | |
| 2182 | MockWrite data_writes2[] = { |
| 2183 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2184 | "Host: www.borked.com\r\n" |
| 2185 | "Connection: keep-alive\r\n\r\n"), |
| 2186 | }; |
| 2187 | |
| 2188 | MockRead data_reads2[] = { |
| 2189 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2190 | "Content-Length: 3\r\n\r\n" |
| 2191 | "foo"), |
| 2192 | }; |
| 2193 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2194 | data_writes1, arraysize(data_writes1)); |
| 2195 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2196 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2197 | data_writes2, arraysize(data_writes2)); |
| 2198 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2199 | |
| 2200 | TestCompletionCallback callback; |
| 2201 | HttpRequestInfo request1; |
| 2202 | request1.method = "GET"; |
| 2203 | request1.url = GURL("http://www.borked.com/"); |
| 2204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2205 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2206 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2207 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2208 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2209 | |
| 2210 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2211 | ASSERT_TRUE(response1); |
| 2212 | ASSERT_TRUE(response1->headers); |
| 2213 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2214 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2215 | |
| 2216 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2217 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2218 | EXPECT_EQ("This server is borked.", response_data1); |
| 2219 | // Deleting the transaction attempts to release the socket back into the |
| 2220 | // socket pool. |
| 2221 | trans1.reset(); |
| 2222 | |
| 2223 | HttpRequestInfo request2; |
| 2224 | request2.method = "GET"; |
| 2225 | request2.url = GURL("http://www.borked.com/foo"); |
| 2226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2227 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2229 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2230 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2231 | |
| 2232 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2233 | ASSERT_TRUE(response2); |
| 2234 | ASSERT_TRUE(response2->headers); |
| 2235 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2236 | |
| 2237 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2238 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2239 | EXPECT_EQ("foo", response_data2); |
| 2240 | } |
| 2241 | |
| 2242 | // This is a little different from the others - it tests the case that the |
| 2243 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2244 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2245 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2246 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2248 | MockWrite data_writes1[] = { |
| 2249 | MockWrite("GET / HTTP/1.1\r\n" |
| 2250 | "Host: www.borked.com\r\n" |
| 2251 | "Connection: keep-alive\r\n\r\n"), |
| 2252 | }; |
| 2253 | |
| 2254 | MockRead data_reads1[] = { |
| 2255 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2256 | "Connection: keep-alive\r\n" |
| 2257 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2258 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2259 | MockRead("0\r\n\r\nBonus data!"), |
| 2260 | }; |
| 2261 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2262 | data_writes1, arraysize(data_writes1)); |
| 2263 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2264 | |
| 2265 | TestCompletionCallback callback; |
| 2266 | HttpRequestInfo request1; |
| 2267 | request1.method = "GET"; |
| 2268 | request1.url = GURL("http://www.borked.com/"); |
| 2269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2270 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2271 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2272 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2273 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2274 | |
| 2275 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2276 | ASSERT_TRUE(response1); |
| 2277 | ASSERT_TRUE(response1->headers); |
| 2278 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2279 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2280 | |
| 2281 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2282 | // response body. |
| 2283 | trans1.reset(); |
| 2284 | |
| 2285 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2286 | // socket can't be reused, rather than returning it to the socket pool. |
| 2287 | base::RunLoop().RunUntilIdle(); |
| 2288 | |
| 2289 | // There should be no idle sockets in the pool. |
| 2290 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2291 | } |
| 2292 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2293 | // Test the request-challenge-retry sequence for basic auth. |
| 2294 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2295 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2296 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2298 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2299 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2300 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2301 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2303 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2304 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2305 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2306 | MockWrite( |
| 2307 | "GET / HTTP/1.1\r\n" |
| 2308 | "Host: www.example.org\r\n" |
| 2309 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2310 | }; |
| 2311 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2312 | MockRead data_reads1[] = { |
| 2313 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2314 | // Give a couple authenticate options (only the middle one is actually |
| 2315 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2316 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2317 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2318 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2319 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2320 | // Large content-length -- won't matter, as connection will be reset. |
| 2321 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2322 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2323 | }; |
| 2324 | |
| 2325 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2326 | // be issuing -- the final header line contains the credentials. |
| 2327 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2328 | MockWrite( |
| 2329 | "GET / HTTP/1.1\r\n" |
| 2330 | "Host: www.example.org\r\n" |
| 2331 | "Connection: keep-alive\r\n" |
| 2332 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2333 | }; |
| 2334 | |
| 2335 | // Lastly, the server responds with the actual content. |
| 2336 | MockRead data_reads2[] = { |
| 2337 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2338 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2339 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2340 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2341 | }; |
| 2342 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2343 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2344 | data_writes1, arraysize(data_writes1)); |
| 2345 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2346 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2347 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2348 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2350 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2351 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2352 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2354 | |
| 2355 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2357 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2358 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2359 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2360 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2361 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2362 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2363 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2364 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2365 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2368 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2369 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2371 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2373 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2375 | |
| 2376 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2377 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2378 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2379 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2380 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2381 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2382 | // The load timing after restart should have a new socket ID, and times after |
| 2383 | // those of the first load timing. |
| 2384 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2385 | load_timing_info2.connect_timing.connect_start); |
| 2386 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2387 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2388 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2389 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2390 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2391 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2393 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2394 | ASSERT_TRUE(response); |
| 2395 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2396 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2397 | } |
| 2398 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2399 | // Test the request-challenge-retry sequence for basic auth. |
| 2400 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2401 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2402 | HttpRequestInfo request; |
| 2403 | request.method = "GET"; |
| 2404 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2405 | |
| 2406 | TestNetLog log; |
| 2407 | MockHostResolver* resolver = new MockHostResolver(); |
| 2408 | session_deps_.net_log = &log; |
| 2409 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2410 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2412 | |
| 2413 | resolver->rules()->ClearRules(); |
| 2414 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2415 | |
| 2416 | MockWrite data_writes1[] = { |
| 2417 | MockWrite("GET / HTTP/1.1\r\n" |
| 2418 | "Host: www.example.org\r\n" |
| 2419 | "Connection: keep-alive\r\n\r\n"), |
| 2420 | }; |
| 2421 | |
| 2422 | MockRead data_reads1[] = { |
| 2423 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2424 | // Give a couple authenticate options (only the middle one is actually |
| 2425 | // supported). |
| 2426 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2427 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2428 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2429 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2430 | // Large content-length -- won't matter, as connection will be reset. |
| 2431 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2432 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2433 | }; |
| 2434 | |
| 2435 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2436 | // be issuing -- the final header line contains the credentials. |
| 2437 | MockWrite data_writes2[] = { |
| 2438 | MockWrite("GET / HTTP/1.1\r\n" |
| 2439 | "Host: www.example.org\r\n" |
| 2440 | "Connection: keep-alive\r\n" |
| 2441 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2442 | }; |
| 2443 | |
| 2444 | // Lastly, the server responds with the actual content. |
| 2445 | MockRead data_reads2[] = { |
| 2446 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2448 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2449 | }; |
| 2450 | |
| 2451 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2452 | data_writes1, arraysize(data_writes1)); |
| 2453 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2454 | data_writes2, arraysize(data_writes2)); |
| 2455 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2456 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2457 | |
| 2458 | TestCompletionCallback callback1; |
| 2459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2460 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2461 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2462 | |
| 2463 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2464 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2465 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2466 | |
| 2467 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2468 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2469 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2470 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2472 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2473 | ASSERT_TRUE(response); |
| 2474 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2475 | |
| 2476 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2477 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2478 | ASSERT_FALSE(endpoint.address().empty()); |
| 2479 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2480 | |
| 2481 | resolver->rules()->ClearRules(); |
| 2482 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2483 | |
| 2484 | TestCompletionCallback callback2; |
| 2485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2486 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2487 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2488 | |
| 2489 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2490 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2491 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2492 | // The load timing after restart should have a new socket ID, and times after |
| 2493 | // those of the first load timing. |
| 2494 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2495 | load_timing_info2.connect_timing.connect_start); |
| 2496 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2497 | |
| 2498 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2499 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2500 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2501 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2503 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2504 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2505 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2506 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2508 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2509 | ASSERT_FALSE(endpoint.address().empty()); |
| 2510 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2511 | } |
| 2512 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2513 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2514 | HttpRequestInfo request; |
| 2515 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2516 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2517 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2518 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2520 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2521 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2522 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2523 | MockWrite( |
| 2524 | "GET / HTTP/1.1\r\n" |
| 2525 | "Host: www.example.org\r\n" |
| 2526 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2527 | }; |
| 2528 | |
| 2529 | MockRead data_reads[] = { |
| 2530 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2531 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2532 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2533 | // Large content-length -- won't matter, as connection will be reset. |
| 2534 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2535 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2536 | }; |
| 2537 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2538 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2539 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2540 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2541 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2545 | |
| 2546 | rv = callback.WaitForResult(); |
| 2547 | EXPECT_EQ(0, rv); |
| 2548 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2549 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2550 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2551 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2552 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2555 | ASSERT_TRUE(response); |
| 2556 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2557 | } |
| 2558 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2559 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2560 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2561 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2562 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2563 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2564 | // reused. See http://crbug.com/544255. |
| 2565 | for (int i = 0; i < 2; ++i) { |
| 2566 | HttpRequestInfo request; |
| 2567 | request.method = "GET"; |
| 2568 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2569 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2570 | TestNetLog log; |
| 2571 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2573 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2574 | MockWrite data_writes[] = { |
| 2575 | MockWrite(ASYNC, 0, |
| 2576 | "GET / HTTP/1.1\r\n" |
| 2577 | "Host: www.example.org\r\n" |
| 2578 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2580 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2581 | // be issuing -- the final header line contains the credentials. |
| 2582 | MockWrite(ASYNC, 6, |
| 2583 | "GET / HTTP/1.1\r\n" |
| 2584 | "Host: www.example.org\r\n" |
| 2585 | "Connection: keep-alive\r\n" |
| 2586 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2587 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2588 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2589 | MockRead data_reads[] = { |
| 2590 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2591 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2592 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2593 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2594 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2595 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2596 | // Lastly, the server responds with the actual content. |
| 2597 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2598 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2599 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2600 | MockRead(ASYNC, 10, "Hello"), |
| 2601 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2602 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2603 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2604 | arraysize(data_writes)); |
| 2605 | data.set_busy_before_sync_reads(true); |
| 2606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2607 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2608 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2611 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2612 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2613 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2614 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2615 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2616 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2618 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2619 | ASSERT_TRUE(response); |
| 2620 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2621 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2622 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2624 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2625 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2626 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2627 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2628 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2629 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2630 | TestLoadTimingReused(load_timing_info2); |
| 2631 | // The load timing after restart should have the same socket ID, and times |
| 2632 | // those of the first load timing. |
| 2633 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2634 | load_timing_info2.send_start); |
| 2635 | 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] | 2636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2637 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2638 | ASSERT_TRUE(response); |
| 2639 | EXPECT_FALSE(response->auth_challenge); |
| 2640 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2641 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2642 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2643 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2644 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2645 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2646 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2647 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2648 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2649 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2653 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2654 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2655 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2657 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2660 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2661 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2662 | MockWrite("GET / HTTP/1.1\r\n" |
| 2663 | "Host: www.example.org\r\n" |
| 2664 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2666 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2667 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2668 | MockWrite("GET / HTTP/1.1\r\n" |
| 2669 | "Host: www.example.org\r\n" |
| 2670 | "Connection: keep-alive\r\n" |
| 2671 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2672 | }; |
| 2673 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | MockRead data_reads1[] = { |
| 2675 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2676 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2677 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2678 | |
| 2679 | // Lastly, the server responds with the actual content. |
| 2680 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2681 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2682 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2683 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2684 | }; |
| 2685 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2686 | // An incorrect reconnect would cause this to be read. |
| 2687 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2688 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2689 | }; |
| 2690 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2691 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2692 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2693 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2694 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2695 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2696 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2697 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2698 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2701 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2703 | |
| 2704 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2705 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2706 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2707 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2708 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2709 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2711 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2713 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2715 | |
| 2716 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2719 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2720 | ASSERT_TRUE(response); |
| 2721 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2722 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2726 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2727 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2728 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2729 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2730 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2733 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2735 | MockWrite("GET / HTTP/1.1\r\n" |
| 2736 | "Host: www.example.org\r\n" |
| 2737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2739 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2740 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | MockWrite("GET / HTTP/1.1\r\n" |
| 2742 | "Host: www.example.org\r\n" |
| 2743 | "Connection: keep-alive\r\n" |
| 2744 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | }; |
| 2746 | |
| 2747 | // Respond with 5 kb of response body. |
| 2748 | std::string large_body_string("Unauthorized"); |
| 2749 | large_body_string.append(5 * 1024, ' '); |
| 2750 | large_body_string.append("\r\n"); |
| 2751 | |
| 2752 | MockRead data_reads1[] = { |
| 2753 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2754 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2755 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2756 | // 5134 = 12 + 5 * 1024 + 2 |
| 2757 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2758 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2759 | |
| 2760 | // Lastly, the server responds with the actual content. |
| 2761 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2762 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2763 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2764 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2765 | }; |
| 2766 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2767 | // An incorrect reconnect would cause this to be read. |
| 2768 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2769 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2770 | }; |
| 2771 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2772 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2773 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2774 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2775 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2776 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2777 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2778 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2779 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2782 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | |
| 2785 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2786 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2789 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2790 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2792 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
| 2797 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2798 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2800 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2801 | ASSERT_TRUE(response); |
| 2802 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2803 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2807 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2808 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2809 | HttpRequestInfo request; |
| 2810 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2811 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2814 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2815 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2816 | MockWrite( |
| 2817 | "GET / HTTP/1.1\r\n" |
| 2818 | "Host: www.example.org\r\n" |
| 2819 | "Connection: keep-alive\r\n\r\n"), |
| 2820 | // This simulates the seemingly successful write to a closed connection |
| 2821 | // if the bug is not fixed. |
| 2822 | MockWrite( |
| 2823 | "GET / HTTP/1.1\r\n" |
| 2824 | "Host: www.example.org\r\n" |
| 2825 | "Connection: keep-alive\r\n" |
| 2826 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2827 | }; |
| 2828 | |
| 2829 | MockRead data_reads1[] = { |
| 2830 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2831 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2832 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2833 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2834 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2835 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2836 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2837 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2838 | }; |
| 2839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2840 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2841 | // be issuing -- the final header line contains the credentials. |
| 2842 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2843 | MockWrite( |
| 2844 | "GET / HTTP/1.1\r\n" |
| 2845 | "Host: www.example.org\r\n" |
| 2846 | "Connection: keep-alive\r\n" |
| 2847 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2848 | }; |
| 2849 | |
| 2850 | // Lastly, the server responds with the actual content. |
| 2851 | MockRead data_reads2[] = { |
| 2852 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2853 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2854 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2855 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2856 | }; |
| 2857 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2858 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2859 | data_writes1, arraysize(data_writes1)); |
| 2860 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2861 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2862 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2863 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2865 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2868 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2870 | |
| 2871 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2874 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2875 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2876 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2878 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2880 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2882 | |
| 2883 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2886 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2887 | ASSERT_TRUE(response); |
| 2888 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2889 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2890 | } |
| 2891 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2892 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2893 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2894 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2895 | HttpRequestInfo request; |
| 2896 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2897 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2898 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2899 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2900 | |
| 2901 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2902 | session_deps_.proxy_service = |
| 2903 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2904 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2905 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2907 | |
| 2908 | // Since we have proxy, should try to establish tunnel. |
| 2909 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2910 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2911 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2912 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2913 | }; |
| 2914 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2915 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2916 | // connection. |
| 2917 | MockRead data_reads1[] = { |
| 2918 | // No credentials. |
| 2919 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2920 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2921 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2922 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2923 | // Since the first connection couldn't be reused, need to establish another |
| 2924 | // once given credentials. |
| 2925 | MockWrite data_writes2[] = { |
| 2926 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2927 | // be issuing -- the final header line contains the credentials. |
| 2928 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2929 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2930 | "Proxy-Connection: keep-alive\r\n" |
| 2931 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2932 | |
| 2933 | MockWrite("GET / HTTP/1.1\r\n" |
| 2934 | "Host: www.example.org\r\n" |
| 2935 | "Connection: keep-alive\r\n\r\n"), |
| 2936 | }; |
| 2937 | |
| 2938 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2939 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2940 | |
| 2941 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2942 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2943 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2944 | MockRead(SYNCHRONOUS, "hello"), |
| 2945 | }; |
| 2946 | |
| 2947 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2948 | data_writes1, arraysize(data_writes1)); |
| 2949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2950 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2951 | data_writes2, arraysize(data_writes2)); |
| 2952 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2953 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2955 | |
| 2956 | TestCompletionCallback callback1; |
| 2957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2958 | std::unique_ptr<HttpNetworkTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2959 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2960 | |
| 2961 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2963 | |
| 2964 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2965 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2966 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2967 | log.GetEntries(&entries); |
| 2968 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2969 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2970 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2971 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2972 | entries, pos, |
| 2973 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2974 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2975 | |
| 2976 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2977 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2978 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2979 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2980 | EXPECT_EQ(407, response->headers->response_code()); |
| 2981 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2982 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2983 | |
| 2984 | LoadTimingInfo load_timing_info; |
| 2985 | // CONNECT requests and responses are handled at the connect job level, so |
| 2986 | // the transaction does not yet have a connection. |
| 2987 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2988 | |
| 2989 | TestCompletionCallback callback2; |
| 2990 | |
| 2991 | rv = |
| 2992 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2994 | |
| 2995 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2996 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2997 | |
| 2998 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2999 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3000 | |
| 3001 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3002 | EXPECT_EQ(200, response->headers->response_code()); |
| 3003 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3004 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3005 | |
| 3006 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3007 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3008 | |
| 3009 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3010 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3011 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3012 | |
| 3013 | trans.reset(); |
| 3014 | session->CloseAllConnections(); |
| 3015 | } |
| 3016 | |
| 3017 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3018 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3019 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3020 | HttpRequestInfo request; |
| 3021 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3022 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3023 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3024 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3025 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3026 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3027 | session_deps_.proxy_service = |
| 3028 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3029 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3030 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3032 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3033 | // Since we have proxy, should try to establish tunnel. |
| 3034 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3035 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3036 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3038 | }; |
| 3039 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3040 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3041 | // connection. |
| 3042 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3043 | // No credentials. |
| 3044 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3045 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3046 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3047 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3048 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3049 | MockWrite data_writes2[] = { |
| 3050 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3051 | // be issuing -- the final header line contains the credentials. |
| 3052 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3053 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3054 | "Proxy-Connection: keep-alive\r\n" |
| 3055 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3056 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3057 | MockWrite("GET / HTTP/1.1\r\n" |
| 3058 | "Host: www.example.org\r\n" |
| 3059 | "Connection: keep-alive\r\n\r\n"), |
| 3060 | }; |
| 3061 | |
| 3062 | MockRead data_reads2[] = { |
| 3063 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3064 | |
| 3065 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3066 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3067 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3068 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3069 | }; |
| 3070 | |
| 3071 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3072 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3074 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3075 | data_writes2, arraysize(data_writes2)); |
| 3076 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3077 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3080 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3082 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3085 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3087 | |
| 3088 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3089 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3090 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3091 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3092 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3093 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3094 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3095 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3096 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3097 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3098 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3099 | |
| 3100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3101 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3102 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3103 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3104 | EXPECT_EQ(407, response->headers->response_code()); |
| 3105 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3106 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3107 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3108 | LoadTimingInfo load_timing_info; |
| 3109 | // CONNECT requests and responses are handled at the connect job level, so |
| 3110 | // the transaction does not yet have a connection. |
| 3111 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3113 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3115 | rv = trans->RestartWithAuth( |
| 3116 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3118 | |
| 3119 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3121 | |
| 3122 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3123 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3124 | |
| 3125 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3126 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3127 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3128 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3129 | |
| 3130 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3131 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3132 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3133 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3134 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3135 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3136 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3137 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3138 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3139 | } |
| 3140 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3141 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3142 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3143 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3144 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3145 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3146 | // reused. See http://crbug.com/544255. |
| 3147 | for (int i = 0; i < 2; ++i) { |
| 3148 | HttpRequestInfo request; |
| 3149 | request.method = "GET"; |
| 3150 | request.url = GURL("https://www.example.org/"); |
| 3151 | // Ensure that proxy authentication is attempted even |
| 3152 | // when the no authentication data flag is set. |
| 3153 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3154 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3155 | // Configure against proxy server "myproxy:70". |
| 3156 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3157 | BoundTestNetLog log; |
| 3158 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3162 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3163 | // Since we have proxy, should try to establish tunnel. |
| 3164 | MockWrite data_writes1[] = { |
| 3165 | MockWrite(ASYNC, 0, |
| 3166 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3167 | "Host: www.example.org:443\r\n" |
| 3168 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3170 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3171 | // be issuing -- the final header line contains the credentials. |
| 3172 | MockWrite(ASYNC, 3, |
| 3173 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3174 | "Host: www.example.org:443\r\n" |
| 3175 | "Proxy-Connection: keep-alive\r\n" |
| 3176 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3177 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3178 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3179 | // The proxy responds to the connect with a 407, using a persistent |
| 3180 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3181 | MockRead data_reads1[] = { |
| 3182 | // No credentials. |
| 3183 | MockRead(ASYNC, 1, |
| 3184 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3185 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3186 | "Proxy-Connection: keep-alive\r\n" |
| 3187 | "Content-Length: 10\r\n\r\n"), |
| 3188 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3189 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3190 | // Wrong credentials (wrong password). |
| 3191 | MockRead(ASYNC, 4, |
| 3192 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3193 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3194 | "Proxy-Connection: keep-alive\r\n" |
| 3195 | "Content-Length: 10\r\n\r\n"), |
| 3196 | // No response body because the test stops reading here. |
| 3197 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3198 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3199 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3200 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3201 | arraysize(data_writes1)); |
| 3202 | data1.set_busy_before_sync_reads(true); |
| 3203 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3204 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3205 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3207 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3208 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3209 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3210 | TestNetLogEntry::List entries; |
| 3211 | log.GetEntries(&entries); |
| 3212 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3213 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3214 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3215 | ExpectLogContainsSomewhere( |
| 3216 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3217 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3218 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3221 | ASSERT_TRUE(response); |
| 3222 | ASSERT_TRUE(response->headers); |
| 3223 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3224 | EXPECT_EQ(407, response->headers->response_code()); |
| 3225 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3226 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3227 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3228 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3229 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3230 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3231 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3232 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3233 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3234 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3236 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3237 | ASSERT_TRUE(response); |
| 3238 | ASSERT_TRUE(response->headers); |
| 3239 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3240 | EXPECT_EQ(407, response->headers->response_code()); |
| 3241 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3242 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3243 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3244 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3245 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3246 | // out of scope. |
| 3247 | session->CloseAllConnections(); |
| 3248 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3252 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3253 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3254 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3255 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3256 | // reused. See http://crbug.com/544255. |
| 3257 | for (int i = 0; i < 2; ++i) { |
| 3258 | HttpRequestInfo request; |
| 3259 | request.method = "GET"; |
| 3260 | request.url = GURL("https://www.example.org/"); |
| 3261 | // Ensure that proxy authentication is attempted even |
| 3262 | // when the no authentication data flag is set. |
| 3263 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3264 | |
| 3265 | // Configure against proxy server "myproxy:70". |
| 3266 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3267 | BoundTestNetLog log; |
| 3268 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3271 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3272 | |
| 3273 | // Since we have proxy, should try to establish tunnel. |
| 3274 | MockWrite data_writes1[] = { |
| 3275 | MockWrite(ASYNC, 0, |
| 3276 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3277 | "Host: www.example.org:443\r\n" |
| 3278 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3280 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3281 | // be issuing -- the final header line contains the credentials. |
| 3282 | MockWrite(ASYNC, 3, |
| 3283 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3284 | "Host: www.example.org:443\r\n" |
| 3285 | "Proxy-Connection: keep-alive\r\n" |
| 3286 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3287 | }; |
| 3288 | |
| 3289 | // The proxy responds to the connect with a 407, using a persistent |
| 3290 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3291 | MockRead data_reads1[] = { |
| 3292 | // No credentials. |
| 3293 | MockRead(ASYNC, 1, |
| 3294 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3295 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3296 | "Content-Length: 10\r\n\r\n"), |
| 3297 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3298 | |
| 3299 | // Wrong credentials (wrong password). |
| 3300 | MockRead(ASYNC, 4, |
| 3301 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3302 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3303 | "Content-Length: 10\r\n\r\n"), |
| 3304 | // No response body because the test stops reading here. |
| 3305 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3306 | }; |
| 3307 | |
| 3308 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3309 | arraysize(data_writes1)); |
| 3310 | data1.set_busy_before_sync_reads(true); |
| 3311 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3312 | |
| 3313 | TestCompletionCallback callback1; |
| 3314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3315 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3316 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3317 | |
| 3318 | TestNetLogEntry::List entries; |
| 3319 | log.GetEntries(&entries); |
| 3320 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3321 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3322 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3323 | ExpectLogContainsSomewhere( |
| 3324 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3325 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3326 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3328 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | ASSERT_TRUE(response); |
| 3330 | ASSERT_TRUE(response->headers); |
| 3331 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3332 | EXPECT_EQ(407, response->headers->response_code()); |
| 3333 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3334 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3335 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3336 | |
| 3337 | TestCompletionCallback callback2; |
| 3338 | |
| 3339 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3340 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3341 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3342 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3344 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | ASSERT_TRUE(response); |
| 3346 | ASSERT_TRUE(response->headers); |
| 3347 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3348 | EXPECT_EQ(407, response->headers->response_code()); |
| 3349 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3350 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3351 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3352 | |
| 3353 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3354 | // out of scope. |
| 3355 | session->CloseAllConnections(); |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3360 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3361 | // the case the server sends extra data on the original socket, so it can't be |
| 3362 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3363 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3364 | HttpRequestInfo request; |
| 3365 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3366 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3367 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3368 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3369 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3370 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | session_deps_.proxy_service = |
| 3372 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3373 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3374 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3376 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3377 | // Since we have proxy, should try to establish tunnel. |
| 3378 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3379 | MockWrite(ASYNC, 0, |
| 3380 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3381 | "Host: www.example.org:443\r\n" |
| 3382 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3383 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3384 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3385 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3386 | // extra data, so the socket cannot be reused. |
| 3387 | MockRead data_reads1[] = { |
| 3388 | // No credentials. |
| 3389 | MockRead(ASYNC, 1, |
| 3390 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3391 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3392 | "Content-Length: 10\r\n\r\n"), |
| 3393 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3394 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3395 | }; |
| 3396 | |
| 3397 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3398 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3399 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | MockWrite(ASYNC, 0, |
| 3401 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3402 | "Host: www.example.org:443\r\n" |
| 3403 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3404 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3405 | |
| 3406 | MockWrite(ASYNC, 2, |
| 3407 | "GET / HTTP/1.1\r\n" |
| 3408 | "Host: www.example.org\r\n" |
| 3409 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3410 | }; |
| 3411 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3412 | MockRead data_reads2[] = { |
| 3413 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3414 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | MockRead(ASYNC, 3, |
| 3416 | "HTTP/1.1 200 OK\r\n" |
| 3417 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3418 | "Content-Length: 5\r\n\r\n"), |
| 3419 | // No response body because the test stops reading here. |
| 3420 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3421 | }; |
| 3422 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3423 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3424 | arraysize(data_writes1)); |
| 3425 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3426 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3427 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3428 | arraysize(data_writes2)); |
| 3429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3430 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3433 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3435 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3437 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3438 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3439 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3440 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3441 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3442 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3443 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3444 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3445 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3446 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3447 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3448 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3449 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3450 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3451 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3452 | ASSERT_TRUE(response); |
| 3453 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3454 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3455 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3456 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3457 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3458 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3459 | LoadTimingInfo load_timing_info; |
| 3460 | // CONNECT requests and responses are handled at the connect job level, so |
| 3461 | // the transaction does not yet have a connection. |
| 3462 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3464 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3465 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3466 | rv = |
| 3467 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3468 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3469 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3470 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | EXPECT_EQ(200, response->headers->response_code()); |
| 3472 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3473 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3474 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3475 | // The password prompt info should not be set. |
| 3476 | EXPECT_FALSE(response->auth_challenge); |
| 3477 | |
| 3478 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3479 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3480 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3481 | |
| 3482 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3483 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3484 | } |
| 3485 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3486 | // Test the case a proxy closes a socket while the challenge body is being |
| 3487 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3488 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3489 | HttpRequestInfo request; |
| 3490 | request.method = "GET"; |
| 3491 | request.url = GURL("https://www.example.org/"); |
| 3492 | // Ensure that proxy authentication is attempted even |
| 3493 | // when the no authentication data flag is set. |
| 3494 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3495 | |
| 3496 | // Configure against proxy server "myproxy:70". |
| 3497 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3498 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3501 | |
| 3502 | // Since we have proxy, should try to establish tunnel. |
| 3503 | MockWrite data_writes1[] = { |
| 3504 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3505 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3506 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3507 | }; |
| 3508 | |
| 3509 | // The proxy responds to the connect with a 407, using a persistent |
| 3510 | // connection. |
| 3511 | MockRead data_reads1[] = { |
| 3512 | // No credentials. |
| 3513 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3514 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3515 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3516 | // Server hands up in the middle of the body. |
| 3517 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3518 | }; |
| 3519 | |
| 3520 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3521 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3522 | // be issuing -- the final header line contains the credentials. |
| 3523 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3524 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3525 | "Proxy-Connection: keep-alive\r\n" |
| 3526 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3527 | |
| 3528 | MockWrite("GET / HTTP/1.1\r\n" |
| 3529 | "Host: www.example.org\r\n" |
| 3530 | "Connection: keep-alive\r\n\r\n"), |
| 3531 | }; |
| 3532 | |
| 3533 | MockRead data_reads2[] = { |
| 3534 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3535 | |
| 3536 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3537 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3538 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3539 | MockRead(SYNCHRONOUS, "hello"), |
| 3540 | }; |
| 3541 | |
| 3542 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3543 | data_writes1, arraysize(data_writes1)); |
| 3544 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3545 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3546 | data_writes2, arraysize(data_writes2)); |
| 3547 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3548 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3549 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3550 | |
| 3551 | TestCompletionCallback callback; |
| 3552 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3553 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3554 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3556 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3557 | ASSERT_TRUE(response); |
| 3558 | ASSERT_TRUE(response->headers); |
| 3559 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3560 | EXPECT_EQ(407, response->headers->response_code()); |
| 3561 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3563 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3564 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3566 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3567 | ASSERT_TRUE(response); |
| 3568 | ASSERT_TRUE(response->headers); |
| 3569 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3570 | EXPECT_EQ(200, response->headers->response_code()); |
| 3571 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3572 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3573 | EXPECT_EQ("hello", body); |
| 3574 | } |
| 3575 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3576 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3577 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3578 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3579 | HttpRequestInfo request; |
| 3580 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3581 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3582 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3583 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3584 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3585 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3589 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3590 | // Since we have proxy, should try to establish tunnel. |
| 3591 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3592 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3593 | "Host: www.example.org:443\r\n" |
| 3594 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3595 | }; |
| 3596 | |
| 3597 | // The proxy responds to the connect with a 407. |
| 3598 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3599 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3600 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3601 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3602 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3603 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3604 | }; |
| 3605 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3606 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3607 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3610 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3611 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3612 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3614 | |
| 3615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3618 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3619 | ASSERT_TRUE(response); |
| 3620 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3621 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3622 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3623 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3624 | |
| 3625 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3626 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3627 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3628 | |
| 3629 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3630 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3631 | } |
| 3632 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3633 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3634 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3635 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3636 | HttpRequestInfo request; |
| 3637 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3638 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3639 | |
| 3640 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3641 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3642 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3645 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3646 | |
| 3647 | // Since we have proxy, should try to establish tunnel. |
| 3648 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3649 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3650 | "Host: www.example.org:443\r\n" |
| 3651 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3652 | }; |
| 3653 | |
| 3654 | // The proxy responds to the connect with a 407. |
| 3655 | MockRead data_reads[] = { |
| 3656 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3657 | MockRead("X-Foo: bar\r\n"), |
| 3658 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3659 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3660 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3661 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3662 | }; |
| 3663 | |
| 3664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3665 | arraysize(data_writes)); |
| 3666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3667 | |
| 3668 | TestCompletionCallback callback; |
| 3669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3672 | |
| 3673 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3674 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3676 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3677 | ASSERT_TRUE(response); |
| 3678 | ASSERT_TRUE(response->headers); |
| 3679 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3680 | EXPECT_EQ(407, response->headers->response_code()); |
| 3681 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3682 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3683 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3684 | |
| 3685 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3686 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3687 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3688 | |
| 3689 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3690 | session->CloseAllConnections(); |
| 3691 | } |
| 3692 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3693 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3694 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3695 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3696 | HttpRequestInfo request; |
| 3697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3698 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3699 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3700 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3703 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3704 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3705 | MockWrite( |
| 3706 | "GET / HTTP/1.1\r\n" |
| 3707 | "Host: www.example.org\r\n" |
| 3708 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3709 | }; |
| 3710 | |
| 3711 | MockRead data_reads1[] = { |
| 3712 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3713 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3714 | // Large content-length -- won't matter, as connection will be reset. |
| 3715 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3716 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3717 | }; |
| 3718 | |
| 3719 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3720 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3721 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3723 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3724 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3725 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3727 | |
| 3728 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3729 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3730 | } |
| 3731 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3732 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3733 | // through a non-authenticating proxy. The request should fail with |
| 3734 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3735 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3736 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3737 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3738 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3739 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3740 | HttpRequestInfo request; |
| 3741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3742 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3743 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3744 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3745 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3746 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3747 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3748 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3749 | // Since we have proxy, should try to establish tunnel. |
| 3750 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3751 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3752 | "Host: www.example.org:443\r\n" |
| 3753 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3754 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3755 | MockWrite("GET / HTTP/1.1\r\n" |
| 3756 | "Host: www.example.org\r\n" |
| 3757 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3758 | }; |
| 3759 | |
| 3760 | MockRead data_reads1[] = { |
| 3761 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3762 | |
| 3763 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3764 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3765 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3766 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3767 | }; |
| 3768 | |
| 3769 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3770 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3771 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3772 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3775 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3779 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3781 | |
| 3782 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3783 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3784 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3785 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3786 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3787 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3788 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3789 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3790 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3791 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3792 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3793 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3794 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3795 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3796 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3797 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3798 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3799 | HttpRequestInfo request; |
| 3800 | request.method = "GET"; |
| 3801 | request.url = GURL("https://www.example.org/"); |
| 3802 | |
| 3803 | // Configure against proxy server "myproxy:70". |
| 3804 | session_deps_.proxy_service = |
| 3805 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3807 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3808 | new HttpAuthHandlerMock::Factory()); |
| 3809 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3810 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3811 | mock_handler->set_allows_default_credentials(true); |
| 3812 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3813 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3814 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3815 | |
| 3816 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3817 | NetLog net_log; |
| 3818 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3819 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3820 | |
| 3821 | // Since we have proxy, should try to establish tunnel. |
| 3822 | MockWrite data_writes1[] = { |
| 3823 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3824 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3825 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3826 | }; |
| 3827 | |
| 3828 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3829 | // connection. |
| 3830 | MockRead data_reads1[] = { |
| 3831 | // No credentials. |
| 3832 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3833 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3834 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3835 | }; |
| 3836 | |
| 3837 | // Since the first connection couldn't be reused, need to establish another |
| 3838 | // once given credentials. |
| 3839 | MockWrite data_writes2[] = { |
| 3840 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3841 | // be issuing -- the final header line contains the credentials. |
| 3842 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3843 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3844 | "Proxy-Connection: keep-alive\r\n" |
| 3845 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3846 | |
| 3847 | MockWrite("GET / HTTP/1.1\r\n" |
| 3848 | "Host: www.example.org\r\n" |
| 3849 | "Connection: keep-alive\r\n\r\n"), |
| 3850 | }; |
| 3851 | |
| 3852 | MockRead data_reads2[] = { |
| 3853 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3854 | |
| 3855 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3857 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3858 | MockRead(SYNCHRONOUS, "hello"), |
| 3859 | }; |
| 3860 | |
| 3861 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3862 | data_writes1, arraysize(data_writes1)); |
| 3863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3864 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3865 | data_writes2, arraysize(data_writes2)); |
| 3866 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3867 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3870 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3871 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3872 | |
| 3873 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3874 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3875 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3876 | |
| 3877 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3878 | ASSERT_TRUE(response); |
| 3879 | ASSERT_TRUE(response->headers); |
| 3880 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3881 | EXPECT_EQ(407, response->headers->response_code()); |
| 3882 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3883 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3884 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3885 | |
| 3886 | LoadTimingInfo load_timing_info; |
| 3887 | // CONNECT requests and responses are handled at the connect job level, so |
| 3888 | // the transaction does not yet have a connection. |
| 3889 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3890 | |
| 3891 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3892 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3893 | response = trans->GetResponseInfo(); |
| 3894 | ASSERT_TRUE(response); |
| 3895 | ASSERT_TRUE(response->headers); |
| 3896 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3897 | EXPECT_EQ(200, response->headers->response_code()); |
| 3898 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3899 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3900 | |
| 3901 | // The password prompt info should not be set. |
| 3902 | EXPECT_FALSE(response->auth_challenge); |
| 3903 | |
| 3904 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3905 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3906 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3907 | |
| 3908 | trans.reset(); |
| 3909 | session->CloseAllConnections(); |
| 3910 | } |
| 3911 | |
| 3912 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3913 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3914 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3915 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3916 | HttpRequestInfo request; |
| 3917 | request.method = "GET"; |
| 3918 | request.url = GURL("https://www.example.org/"); |
| 3919 | |
| 3920 | // Configure against proxy server "myproxy:70". |
| 3921 | session_deps_.proxy_service = |
| 3922 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3923 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3924 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3925 | new HttpAuthHandlerMock::Factory()); |
| 3926 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3927 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3928 | mock_handler->set_allows_default_credentials(true); |
| 3929 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3930 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3931 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3932 | |
| 3933 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3934 | NetLog net_log; |
| 3935 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3936 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3937 | |
| 3938 | // Should try to establish tunnel. |
| 3939 | MockWrite data_writes1[] = { |
| 3940 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3941 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3942 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3943 | |
| 3944 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3945 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3946 | "Proxy-Connection: keep-alive\r\n" |
| 3947 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3948 | }; |
| 3949 | |
| 3950 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3951 | // connection. |
| 3952 | MockRead data_reads1[] = { |
| 3953 | // No credentials. |
| 3954 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3955 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3956 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3957 | }; |
| 3958 | |
| 3959 | // Since the first connection was closed, need to establish another once given |
| 3960 | // credentials. |
| 3961 | MockWrite data_writes2[] = { |
| 3962 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3963 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3964 | "Proxy-Connection: keep-alive\r\n" |
| 3965 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3966 | |
| 3967 | MockWrite("GET / HTTP/1.1\r\n" |
| 3968 | "Host: www.example.org\r\n" |
| 3969 | "Connection: keep-alive\r\n\r\n"), |
| 3970 | }; |
| 3971 | |
| 3972 | MockRead data_reads2[] = { |
| 3973 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3974 | |
| 3975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3976 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3977 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3978 | MockRead(SYNCHRONOUS, "hello"), |
| 3979 | }; |
| 3980 | |
| 3981 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3982 | data_writes1, arraysize(data_writes1)); |
| 3983 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3984 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3985 | data_writes2, arraysize(data_writes2)); |
| 3986 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3987 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3990 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3991 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3992 | |
| 3993 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3994 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3995 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3996 | |
| 3997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3998 | ASSERT_TRUE(response); |
| 3999 | ASSERT_TRUE(response->headers); |
| 4000 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4001 | EXPECT_EQ(407, response->headers->response_code()); |
| 4002 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4003 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4004 | EXPECT_FALSE(response->auth_challenge); |
| 4005 | |
| 4006 | LoadTimingInfo load_timing_info; |
| 4007 | // CONNECT requests and responses are handled at the connect job level, so |
| 4008 | // the transaction does not yet have a connection. |
| 4009 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4010 | |
| 4011 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4012 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4013 | |
| 4014 | response = trans->GetResponseInfo(); |
| 4015 | ASSERT_TRUE(response); |
| 4016 | ASSERT_TRUE(response->headers); |
| 4017 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4018 | EXPECT_EQ(200, response->headers->response_code()); |
| 4019 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4020 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4021 | |
| 4022 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4023 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4024 | |
| 4025 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4026 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4027 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4028 | |
| 4029 | trans.reset(); |
| 4030 | session->CloseAllConnections(); |
| 4031 | } |
| 4032 | |
| 4033 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4034 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4035 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4036 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4037 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4038 | HttpRequestInfo request; |
| 4039 | request.method = "GET"; |
| 4040 | request.url = GURL("https://www.example.org/"); |
| 4041 | |
| 4042 | // Configure against proxy server "myproxy:70". |
| 4043 | session_deps_.proxy_service = |
| 4044 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4046 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4047 | new HttpAuthHandlerMock::Factory()); |
| 4048 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4049 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4050 | mock_handler->set_allows_default_credentials(true); |
| 4051 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4052 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4053 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4054 | |
| 4055 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4056 | NetLog net_log; |
| 4057 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4058 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4059 | |
| 4060 | // Should try to establish tunnel. |
| 4061 | MockWrite data_writes1[] = { |
| 4062 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4063 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4065 | |
| 4066 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4067 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4068 | "Proxy-Connection: keep-alive\r\n" |
| 4069 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4070 | }; |
| 4071 | |
| 4072 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4073 | // second request is sent. |
| 4074 | MockRead data_reads1[] = { |
| 4075 | // No credentials. |
| 4076 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4077 | MockRead("Content-Length: 0\r\n"), |
| 4078 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4079 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4080 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4081 | }; |
| 4082 | |
| 4083 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4084 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4085 | // request. |
| 4086 | MockWrite data_writes2[] = { |
| 4087 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4088 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4089 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4090 | }; |
| 4091 | |
| 4092 | // The proxy, having had more than enough of us, just hangs up. |
| 4093 | MockRead data_reads2[] = { |
| 4094 | // No credentials. |
| 4095 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4096 | }; |
| 4097 | |
| 4098 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4099 | data_writes1, arraysize(data_writes1)); |
| 4100 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4101 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4102 | data_writes2, arraysize(data_writes2)); |
| 4103 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4105 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4106 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4107 | |
| 4108 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4109 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4110 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4111 | |
| 4112 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4113 | ASSERT_TRUE(response); |
| 4114 | ASSERT_TRUE(response->headers); |
| 4115 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4116 | EXPECT_EQ(407, response->headers->response_code()); |
| 4117 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4118 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4119 | EXPECT_FALSE(response->auth_challenge); |
| 4120 | |
| 4121 | LoadTimingInfo load_timing_info; |
| 4122 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4123 | |
| 4124 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4125 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4126 | |
| 4127 | trans.reset(); |
| 4128 | session->CloseAllConnections(); |
| 4129 | } |
| 4130 | |
| 4131 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4132 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4133 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4134 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4135 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4136 | HttpRequestInfo request; |
| 4137 | request.method = "GET"; |
| 4138 | request.url = GURL("https://www.example.org/"); |
| 4139 | |
| 4140 | // Configure against proxy server "myproxy:70". |
| 4141 | session_deps_.proxy_service = |
| 4142 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4144 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4145 | new HttpAuthHandlerMock::Factory()); |
| 4146 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4147 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4148 | mock_handler->set_allows_default_credentials(true); |
| 4149 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4150 | HttpAuth::AUTH_PROXY); |
| 4151 | // Add another handler for the second challenge. It supports default |
| 4152 | // credentials, but they shouldn't be used, since they were already tried. |
| 4153 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4154 | mock_handler->set_allows_default_credentials(true); |
| 4155 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4156 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4157 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4158 | |
| 4159 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4160 | NetLog net_log; |
| 4161 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4162 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4163 | |
| 4164 | // Should try to establish tunnel. |
| 4165 | MockWrite data_writes1[] = { |
| 4166 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4167 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4168 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4169 | }; |
| 4170 | |
| 4171 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4172 | // connection. |
| 4173 | MockRead data_reads1[] = { |
| 4174 | // No credentials. |
| 4175 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4176 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4177 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4178 | }; |
| 4179 | |
| 4180 | // Since the first connection was closed, need to establish another once given |
| 4181 | // credentials. |
| 4182 | MockWrite data_writes2[] = { |
| 4183 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4184 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4185 | "Proxy-Connection: keep-alive\r\n" |
| 4186 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4187 | }; |
| 4188 | |
| 4189 | MockRead data_reads2[] = { |
| 4190 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4191 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4192 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4193 | }; |
| 4194 | |
| 4195 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4196 | data_writes1, arraysize(data_writes1)); |
| 4197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4198 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4199 | data_writes2, arraysize(data_writes2)); |
| 4200 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4201 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4204 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4206 | |
| 4207 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4208 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4209 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4210 | |
| 4211 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4212 | ASSERT_TRUE(response); |
| 4213 | ASSERT_TRUE(response->headers); |
| 4214 | EXPECT_EQ(407, response->headers->response_code()); |
| 4215 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4216 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4217 | EXPECT_FALSE(response->auth_challenge); |
| 4218 | |
| 4219 | LoadTimingInfo load_timing_info; |
| 4220 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4221 | |
| 4222 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | response = trans->GetResponseInfo(); |
| 4225 | ASSERT_TRUE(response); |
| 4226 | ASSERT_TRUE(response->headers); |
| 4227 | EXPECT_EQ(407, response->headers->response_code()); |
| 4228 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4229 | EXPECT_TRUE(response->auth_challenge); |
| 4230 | |
| 4231 | trans.reset(); |
| 4232 | session->CloseAllConnections(); |
| 4233 | } |
| 4234 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4235 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4236 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4237 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4238 | // authentication handshake can continue with the same scheme but with a |
| 4239 | // different identity. |
| 4240 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4241 | HttpRequestInfo request; |
| 4242 | request.method = "GET"; |
| 4243 | request.url = GURL("http://www.example.org/"); |
| 4244 | |
| 4245 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 4246 | new HttpAuthHandlerMock::Factory()); |
| 4247 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4248 | |
| 4249 | // First handler. Uses default credentials, but barfs at generate auth token. |
| 4250 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 4251 | mock_handler->set_allows_default_credentials(true); |
| 4252 | mock_handler->set_allows_explicit_credentials(true); |
| 4253 | mock_handler->set_connection_based(true); |
| 4254 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4255 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4256 | HttpAuth::AUTH_SERVER); |
| 4257 | |
| 4258 | // Add another handler for the second challenge. It supports default |
| 4259 | // credentials, but they shouldn't be used, since they were already tried. |
| 4260 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4261 | mock_handler->set_allows_default_credentials(true); |
| 4262 | mock_handler->set_allows_explicit_credentials(true); |
| 4263 | mock_handler->set_connection_based(true); |
| 4264 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4265 | HttpAuth::AUTH_SERVER); |
| 4266 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4267 | |
| 4268 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4269 | |
| 4270 | MockWrite data_writes1[] = { |
| 4271 | MockWrite("GET / HTTP/1.1\r\n" |
| 4272 | "Host: www.example.org\r\n" |
| 4273 | "Connection: keep-alive\r\n\r\n"), |
| 4274 | }; |
| 4275 | |
| 4276 | MockRead data_reads1[] = { |
| 4277 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4278 | "WWW-Authenticate: Mock\r\n" |
| 4279 | "Connection: keep-alive\r\n\r\n"), |
| 4280 | }; |
| 4281 | |
| 4282 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4283 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4284 | // transaction procceds without an authorization header. |
| 4285 | MockWrite data_writes2[] = { |
| 4286 | MockWrite("GET / HTTP/1.1\r\n" |
| 4287 | "Host: www.example.org\r\n" |
| 4288 | "Connection: keep-alive\r\n\r\n"), |
| 4289 | }; |
| 4290 | |
| 4291 | MockRead data_reads2[] = { |
| 4292 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4293 | "WWW-Authenticate: Mock\r\n" |
| 4294 | "Connection: keep-alive\r\n\r\n"), |
| 4295 | }; |
| 4296 | |
| 4297 | MockWrite data_writes3[] = { |
| 4298 | MockWrite("GET / HTTP/1.1\r\n" |
| 4299 | "Host: www.example.org\r\n" |
| 4300 | "Connection: keep-alive\r\n" |
| 4301 | "Authorization: auth_token\r\n\r\n"), |
| 4302 | }; |
| 4303 | |
| 4304 | MockRead data_reads3[] = { |
| 4305 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4306 | "Content-Length: 5\r\n" |
| 4307 | "Content-Type: text/plain\r\n" |
| 4308 | "Connection: keep-alive\r\n\r\n" |
| 4309 | "Hello"), |
| 4310 | }; |
| 4311 | |
| 4312 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4313 | data_writes1, arraysize(data_writes1)); |
| 4314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4315 | |
| 4316 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4317 | data_writes2, arraysize(data_writes2)); |
| 4318 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4319 | |
| 4320 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4321 | data_writes3, arraysize(data_writes3)); |
| 4322 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4323 | |
| 4324 | std::unique_ptr<HttpNetworkTransaction> trans( |
| 4325 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4326 | |
| 4327 | TestCompletionCallback callback; |
| 4328 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4329 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4330 | |
| 4331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4332 | ASSERT_TRUE(response); |
| 4333 | ASSERT_TRUE(response->headers); |
| 4334 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4335 | |
| 4336 | // The following three tests assert that an authentication challenge was |
| 4337 | // received and that the stack is ready to respond to the challenge using |
| 4338 | // ambient credentials. |
| 4339 | EXPECT_EQ(401, response->headers->response_code()); |
| 4340 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4341 | EXPECT_FALSE(response->auth_challenge); |
| 4342 | |
| 4343 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4344 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4345 | response = trans->GetResponseInfo(); |
| 4346 | ASSERT_TRUE(response); |
| 4347 | ASSERT_TRUE(response->headers); |
| 4348 | |
| 4349 | // The following three tests assert that an authentication challenge was |
| 4350 | // received and that the stack needs explicit credentials before it is ready |
| 4351 | // to respond to the challenge. |
| 4352 | EXPECT_EQ(401, response->headers->response_code()); |
| 4353 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4354 | EXPECT_TRUE(response->auth_challenge); |
| 4355 | |
| 4356 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4357 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4358 | response = trans->GetResponseInfo(); |
| 4359 | ASSERT_TRUE(response); |
| 4360 | ASSERT_TRUE(response->headers); |
| 4361 | EXPECT_EQ(200, response->headers->response_code()); |
| 4362 | |
| 4363 | trans.reset(); |
| 4364 | session->CloseAllConnections(); |
| 4365 | } |
| 4366 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4367 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4368 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4369 | HttpRequestInfo request1; |
| 4370 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4371 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4372 | |
| 4373 | HttpRequestInfo request2; |
| 4374 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4375 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4376 | |
| 4377 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4378 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4379 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4380 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4382 | |
| 4383 | // Since we have proxy, should try to establish tunnel. |
| 4384 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4385 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4386 | "Host: www.example.org:443\r\n" |
| 4387 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4388 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4389 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4390 | "Host: www.example.org\r\n" |
| 4391 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4392 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4393 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4394 | "Host: www.example.org\r\n" |
| 4395 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4396 | }; |
| 4397 | |
| 4398 | // The proxy responds to the connect with a 407, using a persistent |
| 4399 | // connection. |
| 4400 | MockRead data_reads1[] = { |
| 4401 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4402 | |
| 4403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4404 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4405 | MockRead(SYNCHRONOUS, "1"), |
| 4406 | |
| 4407 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4408 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4409 | MockRead(SYNCHRONOUS, "22"), |
| 4410 | }; |
| 4411 | |
| 4412 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4413 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4415 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4417 | |
| 4418 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4419 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4421 | |
| 4422 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4424 | |
| 4425 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4427 | |
| 4428 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4429 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4430 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4431 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4432 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4433 | |
| 4434 | LoadTimingInfo load_timing_info1; |
| 4435 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4436 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4437 | |
| 4438 | trans1.reset(); |
| 4439 | |
| 4440 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4441 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4443 | |
| 4444 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4446 | |
| 4447 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4448 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4449 | |
| 4450 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4451 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4452 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4453 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4454 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4455 | |
| 4456 | LoadTimingInfo load_timing_info2; |
| 4457 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4458 | TestLoadTimingReused(load_timing_info2); |
| 4459 | |
| 4460 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4461 | |
| 4462 | trans2.reset(); |
| 4463 | session->CloseAllConnections(); |
| 4464 | } |
| 4465 | |
| 4466 | // 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] | 4467 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4468 | HttpRequestInfo request1; |
| 4469 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4471 | |
| 4472 | HttpRequestInfo request2; |
| 4473 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4474 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4475 | |
| 4476 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4477 | session_deps_.proxy_service = |
| 4478 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4479 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4480 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4482 | |
| 4483 | // Since we have proxy, should try to establish tunnel. |
| 4484 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4485 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4486 | "Host: www.example.org:443\r\n" |
| 4487 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4488 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4489 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4490 | "Host: www.example.org\r\n" |
| 4491 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4492 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4493 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4494 | "Host: www.example.org\r\n" |
| 4495 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4496 | }; |
| 4497 | |
| 4498 | // The proxy responds to the connect with a 407, using a persistent |
| 4499 | // connection. |
| 4500 | MockRead data_reads1[] = { |
| 4501 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4502 | |
| 4503 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4504 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4505 | MockRead(SYNCHRONOUS, "1"), |
| 4506 | |
| 4507 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4508 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4509 | MockRead(SYNCHRONOUS, "22"), |
| 4510 | }; |
| 4511 | |
| 4512 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4513 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4515 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4517 | |
| 4518 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4519 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4520 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4521 | |
| 4522 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4524 | |
| 4525 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4526 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | |
| 4528 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4529 | ASSERT_TRUE(response1); |
| 4530 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4531 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4532 | |
| 4533 | LoadTimingInfo load_timing_info1; |
| 4534 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4535 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4536 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4537 | |
| 4538 | trans1.reset(); |
| 4539 | |
| 4540 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4541 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4543 | |
| 4544 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4546 | |
| 4547 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4549 | |
| 4550 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4551 | ASSERT_TRUE(response2); |
| 4552 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4553 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4554 | |
| 4555 | LoadTimingInfo load_timing_info2; |
| 4556 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4557 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4558 | |
| 4559 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4560 | |
| 4561 | trans2.reset(); |
| 4562 | session->CloseAllConnections(); |
| 4563 | } |
| 4564 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4565 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4566 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4567 | HttpRequestInfo request; |
| 4568 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4569 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4570 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4571 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4572 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4573 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4574 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4576 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4577 | // Since we have proxy, should use full url |
| 4578 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4579 | MockWrite( |
| 4580 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4581 | "Host: www.example.org\r\n" |
| 4582 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4583 | }; |
| 4584 | |
| 4585 | MockRead data_reads1[] = { |
| 4586 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4587 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4588 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4590 | }; |
| 4591 | |
| 4592 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4593 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4594 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4595 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4598 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4602 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4604 | |
| 4605 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4607 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4608 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4609 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4610 | TestLoadTimingNotReused(load_timing_info, |
| 4611 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4613 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4614 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4615 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4616 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4617 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4618 | EXPECT_EQ(200, response->headers->response_code()); |
| 4619 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4620 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4621 | |
| 4622 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4623 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4624 | } |
| 4625 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4626 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4627 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4628 | HttpRequestInfo request; |
| 4629 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4630 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4631 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4632 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4633 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4634 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4635 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4636 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4637 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4638 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4639 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4640 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4641 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4642 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4643 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4644 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4645 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4646 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4647 | }; |
| 4648 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4649 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4650 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4651 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4652 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4653 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4654 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4657 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4661 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4663 | |
| 4664 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4665 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4666 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4667 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4668 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4669 | TestLoadTimingNotReused(load_timing_info, |
| 4670 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4672 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4673 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4674 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4675 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4676 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4677 | |
| 4678 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4679 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4680 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4681 | } |
| 4682 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4683 | // Verifies that a session which races and wins against the owning transaction |
| 4684 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4685 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4686 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4687 | HttpRequestInfo request; |
| 4688 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4689 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4690 | |
| 4691 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4692 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4693 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4694 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4696 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4697 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4698 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4699 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4700 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4701 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4702 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4703 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4704 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4705 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4706 | }; |
| 4707 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4708 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4709 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4710 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4711 | |
| 4712 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4713 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4715 | |
| 4716 | TestCompletionCallback callback1; |
| 4717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4719 | |
| 4720 | // Stall the hostname resolution begun by the transaction. |
| 4721 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4722 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4724 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4726 | |
| 4727 | // Race a session to the proxy, which completes first. |
| 4728 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4729 | SpdySessionKey key( |
| 4730 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4731 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4732 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4733 | |
| 4734 | // Unstall the resolution begun by the transaction. |
| 4735 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4736 | session_deps_.host_resolver->ResolveAllPending(); |
| 4737 | |
| 4738 | EXPECT_FALSE(callback1.have_result()); |
| 4739 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4740 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4743 | ASSERT_TRUE(response); |
| 4744 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4745 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4746 | |
| 4747 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4748 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4749 | EXPECT_EQ(kUploadData, response_data); |
| 4750 | } |
| 4751 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4752 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4753 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4754 | HttpRequestInfo request; |
| 4755 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4756 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4757 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4758 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4759 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4760 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4761 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4763 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4764 | // The first request will be a bare GET, the second request will be a |
| 4765 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4766 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4767 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4768 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4769 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4770 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4771 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4772 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4773 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4774 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4775 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4776 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4777 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4778 | }; |
| 4779 | |
| 4780 | // The first response is a 407 proxy authentication challenge, and the second |
| 4781 | // response will be a 200 response since the second request includes a valid |
| 4782 | // Authorization header. |
| 4783 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4784 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4785 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4786 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4787 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4788 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4789 | SpdySerializedFrame body_authentication( |
| 4790 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4791 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4792 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4793 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4794 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4795 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4796 | CreateMockRead(resp_data, 4), |
| 4797 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4798 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4799 | }; |
| 4800 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4801 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4802 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4804 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4805 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4806 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4809 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4813 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4815 | |
| 4816 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4819 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4820 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4821 | ASSERT_TRUE(response); |
| 4822 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4823 | EXPECT_EQ(407, response->headers->response_code()); |
| 4824 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4825 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4827 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4829 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4831 | |
| 4832 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4833 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4835 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4836 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4837 | ASSERT_TRUE(response_restart); |
| 4838 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4839 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4840 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4841 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4842 | } |
| 4843 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4844 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4845 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4846 | HttpRequestInfo request; |
| 4847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4848 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4849 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4850 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4851 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4852 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4853 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4857 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4858 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4859 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4860 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4861 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4862 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4863 | const char get[] = |
| 4864 | "GET / HTTP/1.1\r\n" |
| 4865 | "Host: www.example.org\r\n" |
| 4866 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4867 | SpdySerializedFrame wrapped_get( |
| 4868 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4869 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4870 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4871 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4872 | SpdySerializedFrame wrapped_get_resp( |
| 4873 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4874 | SpdySerializedFrame wrapped_body( |
| 4875 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4876 | SpdySerializedFrame window_update( |
| 4877 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4878 | |
| 4879 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4880 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4881 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4882 | }; |
| 4883 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4884 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4885 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4886 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4887 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4888 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4889 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4890 | }; |
| 4891 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4892 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4893 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4894 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4895 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4896 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4897 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4898 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4899 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4902 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4904 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4906 | |
| 4907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4908 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4909 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4910 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4911 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4912 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4914 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4915 | ASSERT_TRUE(response); |
| 4916 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4917 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4918 | |
| 4919 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4920 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4921 | EXPECT_EQ("1234567890", response_data); |
| 4922 | } |
| 4923 | |
| 4924 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4925 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4926 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4927 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4928 | HttpRequestInfo request; |
| 4929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4930 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4931 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4932 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4933 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4934 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4935 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4937 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4938 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4939 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4940 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4941 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4942 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4943 | // fetch https://www.example.org/ via SPDY |
| 4944 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4945 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4946 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4947 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4948 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4950 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4951 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4952 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4953 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4954 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4955 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4956 | SpdySerializedFrame window_update_get_resp( |
| 4957 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4958 | SpdySerializedFrame window_update_body( |
| 4959 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4960 | |
| 4961 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4962 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4963 | CreateMockWrite(window_update_get_resp, 6), |
| 4964 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4965 | }; |
| 4966 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4967 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4968 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4969 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4970 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4971 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4972 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4973 | }; |
| 4974 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4975 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4976 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4977 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4978 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4979 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4980 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4982 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4983 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4986 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4988 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4990 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4991 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4992 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4993 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4994 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4995 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4996 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4997 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4998 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4999 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5000 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5002 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5003 | ASSERT_TRUE(response); |
| 5004 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5005 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5006 | |
| 5007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5008 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5009 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5013 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5014 | HttpRequestInfo request; |
| 5015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5016 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5017 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5018 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5019 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5020 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5021 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5024 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5025 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5026 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5027 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5028 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5029 | SpdySerializedFrame get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5030 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5031 | |
| 5032 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5033 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | }; |
| 5035 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5036 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5037 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5038 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5039 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5040 | }; |
| 5041 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5042 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5043 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5044 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5045 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5046 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5047 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5049 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5050 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5053 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5054 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5055 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5057 | |
| 5058 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5059 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5060 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5061 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5062 | } |
| 5063 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5064 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5065 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5066 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5067 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5068 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5069 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5070 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5071 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5072 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5073 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5074 | |
| 5075 | HttpRequestInfo request1; |
| 5076 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5077 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5078 | request1.load_flags = 0; |
| 5079 | |
| 5080 | HttpRequestInfo request2; |
| 5081 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5082 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5083 | request2.load_flags = 0; |
| 5084 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5085 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5086 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5087 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5088 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5089 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5090 | // Fetch https://www.example.org/ via HTTP. |
| 5091 | const char get1[] = |
| 5092 | "GET / HTTP/1.1\r\n" |
| 5093 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5094 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5095 | SpdySerializedFrame wrapped_get1( |
| 5096 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5097 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5098 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5099 | SpdySerializedFrame wrapped_get_resp1( |
| 5100 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5101 | SpdySerializedFrame wrapped_body1( |
| 5102 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5103 | SpdySerializedFrame window_update( |
| 5104 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5105 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5106 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5107 | SpdyHeaderBlock connect2_block; |
| 5108 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5109 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5110 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5111 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5112 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5113 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5114 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5115 | // Fetch https://mail.example.org/ via HTTP. |
| 5116 | const char get2[] = |
| 5117 | "GET / HTTP/1.1\r\n" |
| 5118 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5119 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5120 | SpdySerializedFrame wrapped_get2( |
| 5121 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5122 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5123 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5124 | SpdySerializedFrame wrapped_get_resp2( |
| 5125 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5126 | SpdySerializedFrame wrapped_body2( |
| 5127 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5128 | |
| 5129 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5130 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5131 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5132 | }; |
| 5133 | |
| 5134 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5135 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5136 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5137 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5138 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5139 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5140 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5141 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5142 | }; |
| 5143 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5144 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5145 | arraysize(spdy_writes)); |
| 5146 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5147 | |
| 5148 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5149 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5151 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5153 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5155 | |
| 5156 | TestCompletionCallback callback; |
| 5157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5159 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5160 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5161 | |
| 5162 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5163 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5164 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5166 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5167 | ASSERT_TRUE(response); |
| 5168 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5169 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5170 | |
| 5171 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5172 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5173 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5174 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5176 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5177 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5178 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5179 | |
| 5180 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5181 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5182 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5183 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5184 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5185 | |
| 5186 | // The requests should have different IDs, since they each are using their own |
| 5187 | // separate stream. |
| 5188 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5190 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5191 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5195 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5196 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5197 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5198 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5199 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5200 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5201 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5202 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5203 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5204 | |
| 5205 | HttpRequestInfo request1; |
| 5206 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5207 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5208 | request1.load_flags = 0; |
| 5209 | |
| 5210 | HttpRequestInfo request2; |
| 5211 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5212 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5213 | request2.load_flags = 0; |
| 5214 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5215 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5216 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5217 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5218 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5219 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5220 | // Fetch https://www.example.org/ via HTTP. |
| 5221 | const char get1[] = |
| 5222 | "GET / HTTP/1.1\r\n" |
| 5223 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5224 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | SpdySerializedFrame wrapped_get1( |
| 5226 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5227 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5228 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5229 | SpdySerializedFrame wrapped_get_resp1( |
| 5230 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5231 | SpdySerializedFrame wrapped_body1( |
| 5232 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5233 | SpdySerializedFrame window_update( |
| 5234 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5235 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5236 | // Fetch https://www.example.org/2 via HTTP. |
| 5237 | const char get2[] = |
| 5238 | "GET /2 HTTP/1.1\r\n" |
| 5239 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5240 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5241 | SpdySerializedFrame wrapped_get2( |
| 5242 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5243 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5244 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5245 | SpdySerializedFrame wrapped_get_resp2( |
| 5246 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5247 | SpdySerializedFrame wrapped_body2( |
| 5248 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5249 | |
| 5250 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5251 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5252 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5253 | }; |
| 5254 | |
| 5255 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5256 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5257 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5258 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5259 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5260 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5261 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5262 | }; |
| 5263 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5264 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5265 | arraysize(spdy_writes)); |
| 5266 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5267 | |
| 5268 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5269 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5271 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5273 | |
| 5274 | TestCompletionCallback callback; |
| 5275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5276 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5278 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5280 | |
| 5281 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5283 | |
| 5284 | LoadTimingInfo load_timing_info; |
| 5285 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5286 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5287 | |
| 5288 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5289 | ASSERT_TRUE(response); |
| 5290 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5291 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5292 | |
| 5293 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5294 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5295 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5296 | trans.reset(); |
| 5297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5298 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5300 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5302 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5303 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5305 | |
| 5306 | LoadTimingInfo load_timing_info2; |
| 5307 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5308 | TestLoadTimingReused(load_timing_info2); |
| 5309 | |
| 5310 | // The requests should have the same ID. |
| 5311 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5312 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5313 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5317 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5318 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5319 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5320 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5321 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5322 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5323 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5324 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5325 | |
| 5326 | HttpRequestInfo request1; |
| 5327 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5328 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5329 | request1.load_flags = 0; |
| 5330 | |
| 5331 | HttpRequestInfo request2; |
| 5332 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5333 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5334 | request2.load_flags = 0; |
| 5335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5336 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5337 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5338 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5339 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5340 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5341 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5342 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5343 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5344 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5345 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5346 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5347 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5348 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5349 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5350 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | SpdySerializedFrame body2( |
| 5352 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5353 | |
| 5354 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5355 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5356 | }; |
| 5357 | |
| 5358 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5359 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5360 | CreateMockRead(body1, 2, ASYNC), |
| 5361 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5362 | CreateMockRead(body2, 5, ASYNC), |
| 5363 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5364 | }; |
| 5365 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5366 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5367 | arraysize(spdy_writes)); |
| 5368 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5369 | |
| 5370 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5371 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5373 | |
| 5374 | TestCompletionCallback callback; |
| 5375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5376 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5377 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5378 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5379 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5380 | |
| 5381 | LoadTimingInfo load_timing_info; |
| 5382 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5383 | TestLoadTimingNotReused(load_timing_info, |
| 5384 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5385 | |
| 5386 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5387 | ASSERT_TRUE(response); |
| 5388 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5389 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5390 | |
| 5391 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5392 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5393 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5394 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5395 | // Delete the first request, so the second one can reuse the socket. |
| 5396 | trans.reset(); |
| 5397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5398 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5399 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5400 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5401 | |
| 5402 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5403 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5404 | TestLoadTimingReused(load_timing_info2); |
| 5405 | |
| 5406 | // The requests should have the same ID. |
| 5407 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5409 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5410 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5411 | } |
| 5412 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5413 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5414 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5415 | HttpRequestInfo request; |
| 5416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5417 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5419 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5421 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5422 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5423 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5424 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5426 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5427 | // Since we have proxy, should use full url |
| 5428 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5429 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5430 | "Host: www.example.org\r\n" |
| 5431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5433 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5434 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5435 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5436 | "Host: www.example.org\r\n" |
| 5437 | "Proxy-Connection: keep-alive\r\n" |
| 5438 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5439 | }; |
| 5440 | |
| 5441 | // The proxy responds to the GET with a 407, using a persistent |
| 5442 | // connection. |
| 5443 | MockRead data_reads1[] = { |
| 5444 | // No credentials. |
| 5445 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5446 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5447 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5448 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5449 | |
| 5450 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5451 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5452 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5453 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5454 | }; |
| 5455 | |
| 5456 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5457 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5458 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5459 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5462 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5463 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5466 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5468 | |
| 5469 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5471 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5472 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5474 | TestLoadTimingNotReused(load_timing_info, |
| 5475 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5478 | ASSERT_TRUE(response); |
| 5479 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5480 | EXPECT_EQ(407, response->headers->response_code()); |
| 5481 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5482 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5484 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5486 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5488 | |
| 5489 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5491 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5492 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5494 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5495 | TestLoadTimingReused(load_timing_info); |
| 5496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5497 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5498 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5499 | |
| 5500 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5501 | EXPECT_EQ(200, response->headers->response_code()); |
| 5502 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5503 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5504 | |
| 5505 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5506 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5507 | } |
| 5508 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5509 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5510 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5511 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5512 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5513 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5514 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5515 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5516 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5517 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5518 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5519 | // Since we have proxy, should try to establish tunnel. |
| 5520 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5521 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5522 | "Host: www.example.org:443\r\n" |
| 5523 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5524 | }; |
| 5525 | |
| 5526 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5527 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5528 | // No response body because the test stops reading here. |
| 5529 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5530 | }; |
| 5531 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5532 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5533 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5536 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5539 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5540 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5542 | |
| 5543 | rv = callback.WaitForResult(); |
| 5544 | EXPECT_EQ(expected_status, rv); |
| 5545 | } |
| 5546 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5547 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5548 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5549 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5550 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5551 | } |
| 5552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5553 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5554 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5555 | } |
| 5556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5558 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5559 | } |
| 5560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5561 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5562 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5563 | } |
| 5564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5565 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5566 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5567 | } |
| 5568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5569 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5570 | ConnectStatusHelper( |
| 5571 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5572 | } |
| 5573 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5574 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5575 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5576 | } |
| 5577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5578 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5579 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5580 | } |
| 5581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5582 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5583 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5584 | } |
| 5585 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5586 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5587 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5588 | } |
| 5589 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5590 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5591 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5592 | } |
| 5593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5594 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5595 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5596 | } |
| 5597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5598 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5599 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5600 | } |
| 5601 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5602 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5603 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5604 | } |
| 5605 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5606 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5607 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5608 | } |
| 5609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5610 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5611 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5612 | } |
| 5613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5614 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5615 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5616 | } |
| 5617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5618 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5619 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5620 | } |
| 5621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5622 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5623 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5624 | } |
| 5625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5626 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5627 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5628 | } |
| 5629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5630 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5631 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5632 | } |
| 5633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5634 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5635 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5636 | } |
| 5637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5638 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5639 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5640 | } |
| 5641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5642 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5643 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5644 | } |
| 5645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5646 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5647 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5648 | } |
| 5649 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5650 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5651 | ConnectStatusHelperWithExpectedStatus( |
| 5652 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5653 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5654 | } |
| 5655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5656 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5658 | } |
| 5659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5661 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5662 | } |
| 5663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5666 | } |
| 5667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5668 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5669 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5670 | } |
| 5671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5672 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5673 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5674 | } |
| 5675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5677 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5678 | } |
| 5679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5680 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5681 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5682 | } |
| 5683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5684 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5685 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5686 | } |
| 5687 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5688 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5689 | ConnectStatusHelper( |
| 5690 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5691 | } |
| 5692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5693 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5694 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5695 | } |
| 5696 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5697 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5698 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5699 | } |
| 5700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5701 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5702 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5703 | } |
| 5704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5705 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5706 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5707 | } |
| 5708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5709 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5710 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5711 | } |
| 5712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5713 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5714 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5715 | } |
| 5716 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5717 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5718 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5719 | } |
| 5720 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5721 | // Test the flow when both the proxy server AND origin server require |
| 5722 | // authentication. Again, this uses basic auth for both since that is |
| 5723 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5724 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5725 | HttpRequestInfo request; |
| 5726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5727 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5728 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5729 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5730 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5734 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5735 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5736 | MockWrite( |
| 5737 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5738 | "Host: www.example.org\r\n" |
| 5739 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5740 | }; |
| 5741 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5742 | MockRead data_reads1[] = { |
| 5743 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5744 | // Give a couple authenticate options (only the middle one is actually |
| 5745 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5746 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5747 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5748 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5749 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5750 | // Large content-length -- won't matter, as connection will be reset. |
| 5751 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5752 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5753 | }; |
| 5754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5755 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5756 | // request we should be issuing -- the final header line contains the |
| 5757 | // proxy's credentials. |
| 5758 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5759 | MockWrite( |
| 5760 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5761 | "Host: www.example.org\r\n" |
| 5762 | "Proxy-Connection: keep-alive\r\n" |
| 5763 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5764 | }; |
| 5765 | |
| 5766 | // Now the proxy server lets the request pass through to origin server. |
| 5767 | // The origin server responds with a 401. |
| 5768 | MockRead data_reads2[] = { |
| 5769 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5770 | // Note: We are using the same realm-name as the proxy server. This is |
| 5771 | // completely valid, as realms are unique across hosts. |
| 5772 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5773 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5774 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5775 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5776 | }; |
| 5777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5778 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5779 | // the credentials for both the proxy and origin server. |
| 5780 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5781 | MockWrite( |
| 5782 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5783 | "Host: www.example.org\r\n" |
| 5784 | "Proxy-Connection: keep-alive\r\n" |
| 5785 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5786 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5787 | }; |
| 5788 | |
| 5789 | // Lastly we get the desired content. |
| 5790 | MockRead data_reads3[] = { |
| 5791 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5792 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5793 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5795 | }; |
| 5796 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5797 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5798 | data_writes1, arraysize(data_writes1)); |
| 5799 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5800 | data_writes2, arraysize(data_writes2)); |
| 5801 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5802 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5804 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5805 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5807 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5808 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5809 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5811 | |
| 5812 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5815 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5816 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5817 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5819 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5821 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5823 | |
| 5824 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5827 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5828 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5829 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5831 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5834 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5836 | |
| 5837 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5840 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5841 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5842 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5843 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5844 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5845 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5846 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5847 | // authorization headers. |
| 5848 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5849 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5850 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5851 | // bytes in the debugger. |
| 5852 | |
| 5853 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5854 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5855 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5856 | request.method = "GET"; |
| 5857 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5858 | |
| 5859 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5860 | // to other auth schemes. |
| 5861 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5862 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5863 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5864 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5866 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5867 | MockWrite data_writes1[] = { |
| 5868 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5869 | "Host: 172.22.68.17\r\n" |
| 5870 | "Connection: keep-alive\r\n\r\n"), |
| 5871 | }; |
| 5872 | |
| 5873 | MockRead data_reads1[] = { |
| 5874 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5875 | // Negotiate and NTLM are often requested together. However, we only want |
| 5876 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5877 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5878 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5879 | MockRead("Connection: close\r\n"), |
| 5880 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5881 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5882 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5883 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5884 | }; |
| 5885 | |
| 5886 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5887 | // After restarting with a null identity, this is the |
| 5888 | // request we should be issuing -- the final header line contains a Type |
| 5889 | // 1 message. |
| 5890 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5891 | "Host: 172.22.68.17\r\n" |
| 5892 | "Connection: keep-alive\r\n" |
| 5893 | "Authorization: NTLM " |
| 5894 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5896 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5897 | // (the credentials for the origin server). The second request continues |
| 5898 | // on the same connection. |
| 5899 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5900 | "Host: 172.22.68.17\r\n" |
| 5901 | "Connection: keep-alive\r\n" |
| 5902 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5903 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5904 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5905 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5906 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5907 | }; |
| 5908 | |
| 5909 | MockRead data_reads2[] = { |
| 5910 | // The origin server responds with a Type 2 message. |
| 5911 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5912 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5913 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5914 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5915 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5916 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5917 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5918 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5919 | "BtAAAAAAA=\r\n"), |
| 5920 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5921 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5922 | MockRead("You are not authorized to view this page\r\n"), |
| 5923 | |
| 5924 | // Lastly we get the desired content. |
| 5925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5926 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5927 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5928 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5930 | }; |
| 5931 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5932 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5933 | data_writes1, arraysize(data_writes1)); |
| 5934 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5935 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5936 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5937 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5939 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5943 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5945 | |
| 5946 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5947 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5949 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5952 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5953 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5955 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5957 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5958 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5960 | |
| 5961 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5964 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5966 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5967 | ASSERT_TRUE(response); |
| 5968 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5970 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5972 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5974 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5975 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5978 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5979 | ASSERT_TRUE(response); |
| 5980 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5981 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5982 | } |
| 5983 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5984 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5985 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5986 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5987 | request.method = "GET"; |
| 5988 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5989 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5990 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5991 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5993 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5994 | MockWrite data_writes1[] = { |
| 5995 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5996 | "Host: 172.22.68.17\r\n" |
| 5997 | "Connection: keep-alive\r\n\r\n"), |
| 5998 | }; |
| 5999 | |
| 6000 | MockRead data_reads1[] = { |
| 6001 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6002 | // Negotiate and NTLM are often requested together. However, we only want |
| 6003 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6004 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6005 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6006 | MockRead("Connection: close\r\n"), |
| 6007 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6008 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6009 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6010 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6011 | }; |
| 6012 | |
| 6013 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6014 | // After restarting with a null identity, this is the |
| 6015 | // request we should be issuing -- the final header line contains a Type |
| 6016 | // 1 message. |
| 6017 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6018 | "Host: 172.22.68.17\r\n" |
| 6019 | "Connection: keep-alive\r\n" |
| 6020 | "Authorization: NTLM " |
| 6021 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6022 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6023 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6024 | // (the credentials for the origin server). The second request continues |
| 6025 | // on the same connection. |
| 6026 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6027 | "Host: 172.22.68.17\r\n" |
| 6028 | "Connection: keep-alive\r\n" |
| 6029 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6030 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6031 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6032 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6033 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6034 | }; |
| 6035 | |
| 6036 | MockRead data_reads2[] = { |
| 6037 | // The origin server responds with a Type 2 message. |
| 6038 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6039 | MockRead("WWW-Authenticate: NTLM " |
| 6040 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6041 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6042 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6043 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6044 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6045 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6046 | "BtAAAAAAA=\r\n"), |
| 6047 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6048 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6049 | MockRead("You are not authorized to view this page\r\n"), |
| 6050 | |
| 6051 | // Wrong password. |
| 6052 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6053 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6054 | MockRead("Connection: close\r\n"), |
| 6055 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6056 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6057 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6058 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6059 | }; |
| 6060 | |
| 6061 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6062 | // After restarting with a null identity, this is the |
| 6063 | // request we should be issuing -- the final header line contains a Type |
| 6064 | // 1 message. |
| 6065 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6066 | "Host: 172.22.68.17\r\n" |
| 6067 | "Connection: keep-alive\r\n" |
| 6068 | "Authorization: NTLM " |
| 6069 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6071 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6072 | // (the credentials for the origin server). The second request continues |
| 6073 | // on the same connection. |
| 6074 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6075 | "Host: 172.22.68.17\r\n" |
| 6076 | "Connection: keep-alive\r\n" |
| 6077 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6078 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6079 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6080 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6081 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6082 | }; |
| 6083 | |
| 6084 | MockRead data_reads3[] = { |
| 6085 | // The origin server responds with a Type 2 message. |
| 6086 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6087 | MockRead("WWW-Authenticate: NTLM " |
| 6088 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6089 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6090 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6091 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6092 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6093 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6094 | "BtAAAAAAA=\r\n"), |
| 6095 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6096 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6097 | MockRead("You are not authorized to view this page\r\n"), |
| 6098 | |
| 6099 | // Lastly we get the desired content. |
| 6100 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6101 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6102 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6103 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6105 | }; |
| 6106 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6107 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6108 | data_writes1, arraysize(data_writes1)); |
| 6109 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6110 | data_writes2, arraysize(data_writes2)); |
| 6111 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6112 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6114 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6115 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6117 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6120 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6121 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6123 | |
| 6124 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6125 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6126 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6127 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6129 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6130 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6131 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6133 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6134 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6135 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6136 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6137 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6139 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6140 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6143 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6144 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6147 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6148 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6149 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6151 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6152 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6153 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6155 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6156 | |
| 6157 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6158 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6159 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6161 | |
| 6162 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6165 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6167 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6168 | |
| 6169 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6170 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6172 | |
| 6173 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6174 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6176 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6177 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6178 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6179 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6180 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6181 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6182 | // Test reading a server response which has only headers, and no body. |
| 6183 | // After some maximum number of bytes is consumed, the transaction should |
| 6184 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6185 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6186 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6187 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6188 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6189 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6190 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6191 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6192 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6193 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6194 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6195 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6196 | |
| 6197 | MockRead data_reads[] = { |
| 6198 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6199 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6200 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6201 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6202 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6203 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6206 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6207 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6208 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6210 | |
| 6211 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6212 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6213 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6214 | |
| 6215 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6216 | // establish tunnel. |
| 6217 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6218 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6219 | HttpRequestInfo request; |
| 6220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6221 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6222 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6223 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6224 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6225 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6226 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6228 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6229 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6230 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6231 | // Since we have proxy, should try to establish tunnel. |
| 6232 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6233 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6234 | "Host: www.example.org:443\r\n" |
| 6235 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6236 | }; |
| 6237 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6238 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6239 | // connection. Usually a proxy would return 501 (not implemented), |
| 6240 | // or 200 (tunnel established). |
| 6241 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6242 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6243 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6244 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6245 | }; |
| 6246 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6247 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6248 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6249 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6251 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6253 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6255 | |
| 6256 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6257 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6258 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6259 | // Empty the current queue. This is necessary because idle sockets are |
| 6260 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6261 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6262 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6263 | // We now check to make sure the TCPClientSocket was not added back to |
| 6264 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6265 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6266 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6267 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6268 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6269 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6270 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6271 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6272 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6273 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6274 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6276 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6277 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6281 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6282 | MockRead data_reads[] = { |
| 6283 | // A part of the response body is received with the response headers. |
| 6284 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6285 | // The rest of the response body is received in two parts. |
| 6286 | MockRead("lo"), |
| 6287 | MockRead(" world"), |
| 6288 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6289 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6290 | }; |
| 6291 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6292 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6295 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6297 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6299 | |
| 6300 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6304 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6305 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6306 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6307 | std::string status_line = response->headers->GetStatusLine(); |
| 6308 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6309 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6310 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6311 | |
| 6312 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6313 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6315 | EXPECT_EQ("hello world", response_data); |
| 6316 | |
| 6317 | // Empty the current queue. This is necessary because idle sockets are |
| 6318 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6319 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6320 | |
| 6321 | // 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] | 6322 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6323 | } |
| 6324 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6325 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6326 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6327 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6328 | HttpRequestInfo request; |
| 6329 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6330 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6331 | |
| 6332 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6333 | MockWrite( |
| 6334 | "GET / HTTP/1.1\r\n" |
| 6335 | "Host: www.example.org\r\n" |
| 6336 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6337 | }; |
| 6338 | |
| 6339 | MockRead data_reads[] = { |
| 6340 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6341 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6342 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6343 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6344 | }; |
| 6345 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6346 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6347 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6348 | |
| 6349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6350 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6353 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6358 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6359 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6361 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6363 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6364 | ASSERT_TRUE(response); |
| 6365 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6366 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6367 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6368 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6369 | |
| 6370 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6371 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6373 | EXPECT_EQ("hello world", response_data); |
| 6374 | |
| 6375 | // Empty the current queue. This is necessary because idle sockets are |
| 6376 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6377 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6378 | |
| 6379 | // 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] | 6380 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6384 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6385 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6386 | HttpRequestInfo request; |
| 6387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6388 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6389 | |
| 6390 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6391 | MockWrite( |
| 6392 | "GET / HTTP/1.1\r\n" |
| 6393 | "Host: www.example.org\r\n" |
| 6394 | "Connection: keep-alive\r\n\r\n"), |
| 6395 | MockWrite( |
| 6396 | "GET / HTTP/1.1\r\n" |
| 6397 | "Host: www.example.org\r\n" |
| 6398 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6399 | }; |
| 6400 | |
| 6401 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6402 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6403 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6404 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6405 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6406 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6409 | |
| 6410 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6411 | data_writes, arraysize(data_writes)); |
| 6412 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6413 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6415 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6417 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6418 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6419 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6420 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6421 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6422 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6423 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6424 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6426 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | |
| 6428 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6429 | ASSERT_TRUE(response); |
| 6430 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6431 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6432 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6433 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6434 | |
| 6435 | std::string response_data; |
| 6436 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6438 | EXPECT_EQ("hello world", response_data); |
| 6439 | |
| 6440 | // Empty the current queue. This is necessary because idle sockets are |
| 6441 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6442 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6443 | |
| 6444 | // 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] | 6445 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6446 | |
| 6447 | // Now start the second transaction, which should reuse the previous socket. |
| 6448 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6449 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6450 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6451 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6452 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6454 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6455 | |
| 6456 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6457 | ASSERT_TRUE(response); |
| 6458 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6459 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6460 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6461 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6462 | |
| 6463 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6465 | EXPECT_EQ("hello world", response_data); |
| 6466 | |
| 6467 | // Empty the current queue. This is necessary because idle sockets are |
| 6468 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6469 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6470 | |
| 6471 | // 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] | 6472 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6473 | } |
| 6474 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6475 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6476 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6477 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6478 | HttpRequestInfo request; |
| 6479 | request.method = "GET"; |
| 6480 | request.url = GURL("http://www.example.org/"); |
| 6481 | request.load_flags = 0; |
| 6482 | |
| 6483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6486 | |
| 6487 | MockRead data_reads[] = { |
| 6488 | // A part of the response body is received with the response headers. |
| 6489 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6490 | // The rest of the response body is received in two parts. |
| 6491 | MockRead("lo"), MockRead(" world"), |
| 6492 | MockRead("junk"), // Should not be read!! |
| 6493 | MockRead(SYNCHRONOUS, OK), |
| 6494 | }; |
| 6495 | |
| 6496 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6498 | |
| 6499 | TestCompletionCallback callback; |
| 6500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6503 | |
| 6504 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6506 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6507 | ASSERT_TRUE(response); |
| 6508 | EXPECT_TRUE(response->headers); |
| 6509 | std::string status_line = response->headers->GetStatusLine(); |
| 6510 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6511 | |
| 6512 | // Make memory critical notification and ensure the transaction still has been |
| 6513 | // operating right. |
| 6514 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6515 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6516 | base::RunLoop().RunUntilIdle(); |
| 6517 | |
| 6518 | // Socket should not be flushed as long as it is not idle. |
| 6519 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6520 | |
| 6521 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6522 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6523 | EXPECT_THAT(rv, IsOk()); |
| 6524 | EXPECT_EQ("hello world", response_data); |
| 6525 | |
| 6526 | // Empty the current queue. This is necessary because idle sockets are |
| 6527 | // added to the connection pool asynchronously with a PostTask. |
| 6528 | base::RunLoop().RunUntilIdle(); |
| 6529 | |
| 6530 | // We now check to make sure the socket was added back to the pool. |
| 6531 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6532 | |
| 6533 | // Idle sockets should be flushed now. |
| 6534 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6535 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6536 | base::RunLoop().RunUntilIdle(); |
| 6537 | |
| 6538 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6539 | } |
| 6540 | |
| 6541 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6542 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6543 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6544 | HttpRequestInfo request; |
| 6545 | request.method = "GET"; |
| 6546 | request.url = GURL("https://www.example.org/"); |
| 6547 | request.load_flags = 0; |
| 6548 | |
| 6549 | MockWrite data_writes[] = { |
| 6550 | MockWrite("GET / HTTP/1.1\r\n" |
| 6551 | "Host: www.example.org\r\n" |
| 6552 | "Connection: keep-alive\r\n\r\n"), |
| 6553 | }; |
| 6554 | |
| 6555 | MockRead data_reads[] = { |
| 6556 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6557 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6558 | |
| 6559 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6561 | |
| 6562 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6563 | arraysize(data_writes)); |
| 6564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6565 | |
| 6566 | TestCompletionCallback callback; |
| 6567 | |
| 6568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6570 | |
| 6571 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6572 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6573 | |
| 6574 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6576 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6577 | ASSERT_TRUE(response); |
| 6578 | ASSERT_TRUE(response->headers); |
| 6579 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6580 | |
| 6581 | // Make memory critical notification and ensure the transaction still has been |
| 6582 | // operating right. |
| 6583 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6584 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6585 | base::RunLoop().RunUntilIdle(); |
| 6586 | |
| 6587 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6588 | |
| 6589 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6590 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6591 | EXPECT_THAT(rv, IsOk()); |
| 6592 | EXPECT_EQ("hello world", response_data); |
| 6593 | |
| 6594 | // Empty the current queue. This is necessary because idle sockets are |
| 6595 | // added to the connection pool asynchronously with a PostTask. |
| 6596 | base::RunLoop().RunUntilIdle(); |
| 6597 | |
| 6598 | // We now check to make sure the socket was added back to the pool. |
| 6599 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6600 | |
| 6601 | // Make memory notification once again and ensure idle socket is closed. |
| 6602 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6603 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6604 | base::RunLoop().RunUntilIdle(); |
| 6605 | |
| 6606 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6607 | } |
| 6608 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6609 | // Make sure that we recycle a socket after a zero-length response. |
| 6610 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6611 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6612 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6614 | request.url = GURL( |
| 6615 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6616 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6617 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6618 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6621 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6622 | MockRead data_reads[] = { |
| 6623 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6624 | "Content-Length: 0\r\n" |
| 6625 | "Content-Type: text/html\r\n\r\n"), |
| 6626 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6627 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6628 | }; |
| 6629 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6630 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6631 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6632 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6633 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6634 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6637 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6641 | |
| 6642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6645 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6646 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6647 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6648 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6649 | std::string status_line = response->headers->GetStatusLine(); |
| 6650 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6651 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6652 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6653 | |
| 6654 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6655 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6656 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6657 | EXPECT_EQ("", response_data); |
| 6658 | |
| 6659 | // Empty the current queue. This is necessary because idle sockets are |
| 6660 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6661 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6662 | |
| 6663 | // 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] | 6664 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6665 | } |
| 6666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6667 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6668 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6669 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6670 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6671 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6672 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6673 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6674 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6675 | // after use. |
| 6676 | request[0].method = "GET"; |
| 6677 | request[0].url = GURL("http://www.google.com/"); |
| 6678 | request[0].load_flags = 0; |
| 6679 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6680 | // transaction 1. The first attempts fails when writing the POST data. |
| 6681 | // This causes the transaction to retry with a new socket. The second |
| 6682 | // attempt succeeds. |
| 6683 | request[1].method = "POST"; |
| 6684 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6685 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6686 | request[1].load_flags = 0; |
| 6687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6689 | |
| 6690 | // The first socket is used for transaction 1 and the first attempt of |
| 6691 | // transaction 2. |
| 6692 | |
| 6693 | // The response of transaction 1. |
| 6694 | MockRead data_reads1[] = { |
| 6695 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6696 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6697 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6698 | }; |
| 6699 | // The mock write results of transaction 1 and the first attempt of |
| 6700 | // transaction 2. |
| 6701 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6702 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6703 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6704 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6705 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6706 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6707 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6708 | |
| 6709 | // The second socket is used for the second attempt of transaction 2. |
| 6710 | |
| 6711 | // The response of transaction 2. |
| 6712 | MockRead data_reads2[] = { |
| 6713 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6714 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6716 | }; |
| 6717 | // The mock write results of the second attempt of transaction 2. |
| 6718 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6719 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6720 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6721 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6722 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6723 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6724 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6725 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6726 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6727 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6728 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6729 | "hello world", "welcome" |
| 6730 | }; |
| 6731 | |
| 6732 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6735 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6736 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6737 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6739 | |
| 6740 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6743 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6744 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6745 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6746 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6747 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6748 | |
| 6749 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6750 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6751 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6752 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6753 | } |
| 6754 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6755 | |
| 6756 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6757 | // 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] | 6758 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6759 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6760 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6762 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6763 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6767 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6768 | // The password contains an escaped character -- for this test to pass it |
| 6769 | // will need to be unescaped by HttpNetworkTransaction. |
| 6770 | EXPECT_EQ("b%40r", request.url.password()); |
| 6771 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6773 | MockWrite( |
| 6774 | "GET / HTTP/1.1\r\n" |
| 6775 | "Host: www.example.org\r\n" |
| 6776 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6777 | }; |
| 6778 | |
| 6779 | MockRead data_reads1[] = { |
| 6780 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6781 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6782 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6783 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6784 | }; |
| 6785 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6786 | // After the challenge above, the transaction will be restarted using the |
| 6787 | // identity from the url (foo, b@r) to answer the challenge. |
| 6788 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6789 | MockWrite( |
| 6790 | "GET / HTTP/1.1\r\n" |
| 6791 | "Host: www.example.org\r\n" |
| 6792 | "Connection: keep-alive\r\n" |
| 6793 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6794 | }; |
| 6795 | |
| 6796 | MockRead data_reads2[] = { |
| 6797 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6798 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6799 | MockRead(SYNCHRONOUS, OK), |
| 6800 | }; |
| 6801 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6802 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6803 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6804 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6805 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6809 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6810 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6812 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6813 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6814 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6815 | |
| 6816 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6817 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6819 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6820 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6821 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6823 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6824 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6825 | |
| 6826 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6827 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6828 | |
| 6829 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6830 | |
| 6831 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6832 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6836 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6837 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6838 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6839 | HttpRequestInfo request; |
| 6840 | request.method = "GET"; |
| 6841 | // Note: the URL has a username:password in it. The password "baz" is |
| 6842 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6843 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6844 | |
| 6845 | request.load_flags = LOAD_NORMAL; |
| 6846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6849 | |
| 6850 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6851 | MockWrite( |
| 6852 | "GET / HTTP/1.1\r\n" |
| 6853 | "Host: www.example.org\r\n" |
| 6854 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6855 | }; |
| 6856 | |
| 6857 | MockRead data_reads1[] = { |
| 6858 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6859 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6860 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6861 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6862 | }; |
| 6863 | |
| 6864 | // After the challenge above, the transaction will be restarted using the |
| 6865 | // identity from the url (foo, baz) to answer the challenge. |
| 6866 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6867 | MockWrite( |
| 6868 | "GET / HTTP/1.1\r\n" |
| 6869 | "Host: www.example.org\r\n" |
| 6870 | "Connection: keep-alive\r\n" |
| 6871 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6872 | }; |
| 6873 | |
| 6874 | MockRead data_reads2[] = { |
| 6875 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6876 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6877 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6878 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6879 | }; |
| 6880 | |
| 6881 | // After the challenge above, the transaction will be restarted using the |
| 6882 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6883 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6884 | MockWrite( |
| 6885 | "GET / HTTP/1.1\r\n" |
| 6886 | "Host: www.example.org\r\n" |
| 6887 | "Connection: keep-alive\r\n" |
| 6888 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6889 | }; |
| 6890 | |
| 6891 | MockRead data_reads3[] = { |
| 6892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6893 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6894 | MockRead(SYNCHRONOUS, OK), |
| 6895 | }; |
| 6896 | |
| 6897 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6898 | data_writes1, arraysize(data_writes1)); |
| 6899 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6900 | data_writes2, arraysize(data_writes2)); |
| 6901 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6902 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6903 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6904 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6905 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6906 | |
| 6907 | TestCompletionCallback callback1; |
| 6908 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6909 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6911 | |
| 6912 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6915 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6916 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6917 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6919 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6920 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6921 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6924 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6925 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6926 | |
| 6927 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6928 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6930 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6931 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6932 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6934 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6935 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6936 | |
| 6937 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6938 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6939 | |
| 6940 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6941 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6942 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6943 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6944 | } |
| 6945 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6946 | |
| 6947 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6948 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6949 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6951 | HttpRequestInfo request; |
| 6952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6953 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6954 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6955 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6958 | |
| 6959 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6960 | MockWrite( |
| 6961 | "GET / HTTP/1.1\r\n" |
| 6962 | "Host: www.example.org\r\n" |
| 6963 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6964 | }; |
| 6965 | |
| 6966 | MockRead data_reads1[] = { |
| 6967 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6968 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6969 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6970 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6971 | }; |
| 6972 | |
| 6973 | // After the challenge above, the transaction will be restarted using the |
| 6974 | // identity supplied by the user, not the one in the URL, to answer the |
| 6975 | // challenge. |
| 6976 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6977 | MockWrite( |
| 6978 | "GET / HTTP/1.1\r\n" |
| 6979 | "Host: www.example.org\r\n" |
| 6980 | "Connection: keep-alive\r\n" |
| 6981 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6982 | }; |
| 6983 | |
| 6984 | MockRead data_reads3[] = { |
| 6985 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6986 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6987 | MockRead(SYNCHRONOUS, OK), |
| 6988 | }; |
| 6989 | |
| 6990 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6991 | data_writes1, arraysize(data_writes1)); |
| 6992 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6993 | data_writes3, arraysize(data_writes3)); |
| 6994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6995 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6996 | |
| 6997 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6998 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7000 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7001 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7002 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7004 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7005 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7006 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7007 | |
| 7008 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7009 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7011 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7012 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7013 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7015 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7016 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7017 | |
| 7018 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7019 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7020 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7021 | |
| 7022 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7023 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7024 | } |
| 7025 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7026 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7027 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7029 | |
| 7030 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7031 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7032 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7034 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7037 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7038 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7039 | MockWrite( |
| 7040 | "GET /x/y/z HTTP/1.1\r\n" |
| 7041 | "Host: www.example.org\r\n" |
| 7042 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7043 | }; |
| 7044 | |
| 7045 | MockRead data_reads1[] = { |
| 7046 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7047 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7048 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7049 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7050 | }; |
| 7051 | |
| 7052 | // Resend with authorization (username=foo, password=bar) |
| 7053 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7054 | MockWrite( |
| 7055 | "GET /x/y/z HTTP/1.1\r\n" |
| 7056 | "Host: www.example.org\r\n" |
| 7057 | "Connection: keep-alive\r\n" |
| 7058 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7059 | }; |
| 7060 | |
| 7061 | // Sever accepts the authorization. |
| 7062 | MockRead data_reads2[] = { |
| 7063 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7064 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7065 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7066 | }; |
| 7067 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7068 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7069 | data_writes1, arraysize(data_writes1)); |
| 7070 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7071 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7073 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7075 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7076 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7077 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7078 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7079 | |
| 7080 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7081 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7083 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7084 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7085 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7087 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7089 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7090 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7092 | |
| 7093 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7094 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7095 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7096 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7097 | ASSERT_TRUE(response); |
| 7098 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7099 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7100 | } |
| 7101 | |
| 7102 | // ------------------------------------------------------------------------ |
| 7103 | |
| 7104 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7105 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7106 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7107 | request.method = "GET"; |
| 7108 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7109 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7110 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7112 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7113 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7114 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7115 | MockWrite( |
| 7116 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7117 | "Host: www.example.org\r\n" |
| 7118 | "Connection: keep-alive\r\n" |
| 7119 | // Send preemptive authorization for MyRealm1 |
| 7120 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7121 | }; |
| 7122 | |
| 7123 | // The server didn't like the preemptive authorization, and |
| 7124 | // challenges us for a different realm (MyRealm2). |
| 7125 | MockRead data_reads1[] = { |
| 7126 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7127 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7128 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7129 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7130 | }; |
| 7131 | |
| 7132 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7133 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7134 | MockWrite( |
| 7135 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7136 | "Host: www.example.org\r\n" |
| 7137 | "Connection: keep-alive\r\n" |
| 7138 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7139 | }; |
| 7140 | |
| 7141 | // Sever accepts the authorization. |
| 7142 | MockRead data_reads2[] = { |
| 7143 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7144 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7145 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7146 | }; |
| 7147 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7148 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7149 | data_writes1, arraysize(data_writes1)); |
| 7150 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7151 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7152 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7153 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7155 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7157 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7159 | |
| 7160 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7164 | ASSERT_TRUE(response); |
| 7165 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7166 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7167 | EXPECT_EQ("http://www.example.org", |
| 7168 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7169 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7170 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7172 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7174 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7175 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7177 | |
| 7178 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7181 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7182 | ASSERT_TRUE(response); |
| 7183 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7184 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7185 | } |
| 7186 | |
| 7187 | // ------------------------------------------------------------------------ |
| 7188 | |
| 7189 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7190 | // succeed with preemptive authorization. |
| 7191 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7192 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7194 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7197 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7198 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7199 | MockWrite( |
| 7200 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7201 | "Host: www.example.org\r\n" |
| 7202 | "Connection: keep-alive\r\n" |
| 7203 | // The authorization for MyRealm1 gets sent preemptively |
| 7204 | // (since the url is in the same protection space) |
| 7205 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7206 | }; |
| 7207 | |
| 7208 | // Sever accepts the preemptive authorization |
| 7209 | MockRead data_reads1[] = { |
| 7210 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7211 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7213 | }; |
| 7214 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7215 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7216 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7217 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7219 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7220 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7221 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7223 | |
| 7224 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7228 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7229 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7230 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7231 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7232 | } |
| 7233 | |
| 7234 | // ------------------------------------------------------------------------ |
| 7235 | |
| 7236 | // Transaction 4: request another URL in MyRealm (however the |
| 7237 | // url is not known to belong to the protection space, so no pre-auth). |
| 7238 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7239 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7240 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7241 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7243 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7244 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7245 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7246 | MockWrite( |
| 7247 | "GET /x/1 HTTP/1.1\r\n" |
| 7248 | "Host: www.example.org\r\n" |
| 7249 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7250 | }; |
| 7251 | |
| 7252 | MockRead data_reads1[] = { |
| 7253 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7254 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7255 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7256 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7257 | }; |
| 7258 | |
| 7259 | // Resend with authorization from MyRealm's cache. |
| 7260 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7261 | MockWrite( |
| 7262 | "GET /x/1 HTTP/1.1\r\n" |
| 7263 | "Host: www.example.org\r\n" |
| 7264 | "Connection: keep-alive\r\n" |
| 7265 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7266 | }; |
| 7267 | |
| 7268 | // Sever accepts the authorization. |
| 7269 | MockRead data_reads2[] = { |
| 7270 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7271 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7272 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7273 | }; |
| 7274 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7275 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7276 | data_writes1, arraysize(data_writes1)); |
| 7277 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7278 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7279 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7280 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7282 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7284 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7286 | |
| 7287 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7290 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7291 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7293 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7294 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7295 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7296 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7298 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7299 | ASSERT_TRUE(response); |
| 7300 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7301 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7302 | } |
| 7303 | |
| 7304 | // ------------------------------------------------------------------------ |
| 7305 | |
| 7306 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7307 | // cached identity. Should invalidate and re-prompt. |
| 7308 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7309 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7310 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7311 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7313 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7314 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7315 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7316 | MockWrite( |
| 7317 | "GET /p/q/t HTTP/1.1\r\n" |
| 7318 | "Host: www.example.org\r\n" |
| 7319 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7320 | }; |
| 7321 | |
| 7322 | MockRead data_reads1[] = { |
| 7323 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7324 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7325 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7326 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7327 | }; |
| 7328 | |
| 7329 | // Resend with authorization from cache for MyRealm. |
| 7330 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7331 | MockWrite( |
| 7332 | "GET /p/q/t HTTP/1.1\r\n" |
| 7333 | "Host: www.example.org\r\n" |
| 7334 | "Connection: keep-alive\r\n" |
| 7335 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7336 | }; |
| 7337 | |
| 7338 | // Sever rejects the authorization. |
| 7339 | MockRead data_reads2[] = { |
| 7340 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7341 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7342 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7343 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7344 | }; |
| 7345 | |
| 7346 | // At this point we should prompt for new credentials for MyRealm. |
| 7347 | // Restart with username=foo3, password=foo4. |
| 7348 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7349 | MockWrite( |
| 7350 | "GET /p/q/t HTTP/1.1\r\n" |
| 7351 | "Host: www.example.org\r\n" |
| 7352 | "Connection: keep-alive\r\n" |
| 7353 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7354 | }; |
| 7355 | |
| 7356 | // Sever accepts the authorization. |
| 7357 | MockRead data_reads3[] = { |
| 7358 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7359 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7360 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7361 | }; |
| 7362 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7363 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7364 | data_writes1, arraysize(data_writes1)); |
| 7365 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7366 | data_writes2, arraysize(data_writes2)); |
| 7367 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7368 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7369 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7370 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7371 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7373 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7375 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7377 | |
| 7378 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7381 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7382 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7385 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7386 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7390 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7391 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7393 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7395 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7396 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7399 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7402 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7403 | ASSERT_TRUE(response); |
| 7404 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7405 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7406 | } |
| 7407 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7408 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7409 | // Tests that nonce count increments when multiple auth attempts |
| 7410 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7411 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7412 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7413 | new HttpAuthHandlerDigest::Factory(); |
| 7414 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7415 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7416 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7417 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7419 | |
| 7420 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7421 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7422 | HttpRequestInfo request; |
| 7423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7424 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7425 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7427 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7428 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7429 | MockWrite( |
| 7430 | "GET /x/y/z HTTP/1.1\r\n" |
| 7431 | "Host: www.example.org\r\n" |
| 7432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7433 | }; |
| 7434 | |
| 7435 | MockRead data_reads1[] = { |
| 7436 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7437 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7438 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7439 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7440 | }; |
| 7441 | |
| 7442 | // Resend with authorization (username=foo, password=bar) |
| 7443 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7444 | MockWrite( |
| 7445 | "GET /x/y/z HTTP/1.1\r\n" |
| 7446 | "Host: www.example.org\r\n" |
| 7447 | "Connection: keep-alive\r\n" |
| 7448 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7449 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7450 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7451 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7452 | }; |
| 7453 | |
| 7454 | // Sever accepts the authorization. |
| 7455 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7456 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7457 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7458 | }; |
| 7459 | |
| 7460 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7461 | data_writes1, arraysize(data_writes1)); |
| 7462 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7463 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7464 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7465 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7467 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7469 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7471 | |
| 7472 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7475 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7476 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7477 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7479 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7481 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7482 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7484 | |
| 7485 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7488 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7489 | ASSERT_TRUE(response); |
| 7490 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | // ------------------------------------------------------------------------ |
| 7494 | |
| 7495 | // Transaction 2: Request another resource in digestive's protection space. |
| 7496 | // This will preemptively add an Authorization header which should have an |
| 7497 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7498 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7499 | HttpRequestInfo request; |
| 7500 | request.method = "GET"; |
| 7501 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7502 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7503 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7506 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7507 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7508 | MockWrite( |
| 7509 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7510 | "Host: www.example.org\r\n" |
| 7511 | "Connection: keep-alive\r\n" |
| 7512 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7513 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7514 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7515 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7516 | }; |
| 7517 | |
| 7518 | // Sever accepts the authorization. |
| 7519 | MockRead data_reads1[] = { |
| 7520 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7521 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7522 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7523 | }; |
| 7524 | |
| 7525 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7526 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7527 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7528 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7529 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7531 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7533 | |
| 7534 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7535 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7537 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7538 | ASSERT_TRUE(response); |
| 7539 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7543 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7544 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7545 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7547 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7548 | |
| 7549 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7550 | trans.read_buf_ = new IOBuffer(15); |
| 7551 | trans.read_buf_len_ = 15; |
| 7552 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7553 | |
| 7554 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7555 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7556 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7557 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7558 | response->response_time = base::Time::Now(); |
| 7559 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7560 | |
| 7561 | { // Setup state for response_.vary_data |
| 7562 | HttpRequestInfo request; |
| 7563 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7564 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7565 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7566 | request.extra_headers.SetHeader("Foo", "1"); |
| 7567 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7568 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7569 | } |
| 7570 | |
| 7571 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7572 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7573 | |
| 7574 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7575 | EXPECT_FALSE(trans.read_buf_); |
| 7576 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7577 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7578 | EXPECT_FALSE(response->auth_challenge); |
| 7579 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7580 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7581 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7582 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7583 | } |
| 7584 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7585 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7586 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7587 | HttpRequestInfo request; |
| 7588 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7589 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7593 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7594 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7595 | MockWrite( |
| 7596 | "GET / HTTP/1.1\r\n" |
| 7597 | "Host: www.example.org\r\n" |
| 7598 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7599 | }; |
| 7600 | |
| 7601 | MockRead data_reads[] = { |
| 7602 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7603 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7604 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7606 | }; |
| 7607 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7608 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7609 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7610 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7611 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7612 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7613 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7614 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7619 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7620 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7621 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7622 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7623 | |
| 7624 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7625 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7626 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7627 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7629 | |
| 7630 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7633 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7634 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7635 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7636 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7637 | } |
| 7638 | |
| 7639 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7640 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7641 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7642 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7643 | |
| 7644 | HttpRequestInfo request; |
| 7645 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7646 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7647 | |
| 7648 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7649 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7650 | "Host: www.example.org:443\r\n" |
| 7651 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7652 | }; |
| 7653 | |
| 7654 | MockRead proxy_reads[] = { |
| 7655 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7656 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7657 | }; |
| 7658 | |
| 7659 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7660 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7661 | "Host: www.example.org:443\r\n" |
| 7662 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7663 | MockWrite("GET / HTTP/1.1\r\n" |
| 7664 | "Host: www.example.org\r\n" |
| 7665 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7666 | }; |
| 7667 | |
| 7668 | MockRead data_reads[] = { |
| 7669 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7670 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7671 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7672 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7673 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7674 | }; |
| 7675 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7676 | StaticSocketDataProvider ssl_bad_certificate( |
| 7677 | proxy_reads, arraysize(proxy_reads), |
| 7678 | proxy_writes, arraysize(proxy_writes)); |
| 7679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7680 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7681 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7682 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7683 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7684 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7686 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7689 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7690 | |
| 7691 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7692 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7693 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7696 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7697 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7699 | |
| 7700 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7701 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7703 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7705 | |
| 7706 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7707 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7709 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7710 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7711 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7712 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7713 | } |
| 7714 | } |
| 7715 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7716 | |
| 7717 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7718 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7719 | session_deps_.proxy_service = |
| 7720 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7721 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7722 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7723 | |
| 7724 | HttpRequestInfo request; |
| 7725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7726 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7727 | |
| 7728 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7729 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7730 | "Host: www.example.org:443\r\n" |
| 7731 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7732 | MockWrite("GET / HTTP/1.1\r\n" |
| 7733 | "Host: www.example.org\r\n" |
| 7734 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7735 | }; |
| 7736 | |
| 7737 | MockRead data_reads[] = { |
| 7738 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7739 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7740 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7741 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7743 | }; |
| 7744 | |
| 7745 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7746 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7747 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7748 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7749 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7754 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7755 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7759 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7761 | |
| 7762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7763 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7764 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7765 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7766 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7767 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7768 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7769 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7770 | EXPECT_EQ(200, response->headers->response_code()); |
| 7771 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7772 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7773 | |
| 7774 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7775 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7776 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7777 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7778 | } |
| 7779 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7780 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7781 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7782 | session_deps_.proxy_service = |
| 7783 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7784 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7785 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7786 | |
| 7787 | HttpRequestInfo request; |
| 7788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7789 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7790 | |
| 7791 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7792 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7793 | "Host: www.example.org:443\r\n" |
| 7794 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7795 | }; |
| 7796 | |
| 7797 | MockRead data_reads[] = { |
| 7798 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7799 | MockRead("Location: http://login.example.com/\r\n"), |
| 7800 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7802 | }; |
| 7803 | |
| 7804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7805 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7806 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7811 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7816 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7818 | |
| 7819 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7820 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7822 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7823 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7824 | |
| 7825 | EXPECT_EQ(302, response->headers->response_code()); |
| 7826 | std::string url; |
| 7827 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7828 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7829 | |
| 7830 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7831 | // timing for the proxy connection instead of the connection to the host, |
| 7832 | // and no send / receive times. |
| 7833 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7834 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7835 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7836 | |
| 7837 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7838 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7839 | |
| 7840 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7841 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7842 | load_timing_info.proxy_resolve_end); |
| 7843 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7844 | load_timing_info.connect_timing.connect_start); |
| 7845 | ExpectConnectTimingHasTimes( |
| 7846 | load_timing_info.connect_timing, |
| 7847 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7848 | |
| 7849 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7850 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7851 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7852 | } |
| 7853 | |
| 7854 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7855 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7856 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7857 | |
| 7858 | HttpRequestInfo request; |
| 7859 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7860 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7861 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7862 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7863 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7864 | SpdySerializedFrame goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7865 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7866 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7867 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7868 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7869 | }; |
| 7870 | |
| 7871 | static const char* const kExtraHeaders[] = { |
| 7872 | "location", |
| 7873 | "http://login.example.com/", |
| 7874 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7875 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7876 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7877 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7878 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7879 | }; |
| 7880 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7881 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7882 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7883 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7884 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7885 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7887 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7889 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7896 | |
| 7897 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7898 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7899 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7900 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7901 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7902 | |
| 7903 | EXPECT_EQ(302, response->headers->response_code()); |
| 7904 | std::string url; |
| 7905 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7906 | EXPECT_EQ("http://login.example.com/", url); |
| 7907 | } |
| 7908 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7909 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7910 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7911 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7912 | |
| 7913 | HttpRequestInfo request; |
| 7914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7915 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7916 | |
| 7917 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7918 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7919 | "Host: www.example.org:443\r\n" |
| 7920 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7921 | }; |
| 7922 | |
| 7923 | MockRead data_reads[] = { |
| 7924 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7925 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7926 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7927 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7928 | }; |
| 7929 | |
| 7930 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7931 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7932 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7933 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7937 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7944 | |
| 7945 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7946 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7947 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7948 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7949 | } |
| 7950 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7951 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7952 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7953 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7954 | |
| 7955 | HttpRequestInfo request; |
| 7956 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7957 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7958 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7959 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7960 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7962 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7963 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7964 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7965 | }; |
| 7966 | |
| 7967 | static const char* const kExtraHeaders[] = { |
| 7968 | "location", |
| 7969 | "http://login.example.com/", |
| 7970 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7971 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7972 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7973 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7974 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7975 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7976 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7977 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7978 | }; |
| 7979 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7980 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7981 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7982 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7983 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7984 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7988 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7993 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7995 | |
| 7996 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7997 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7998 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7999 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8000 | } |
| 8001 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8002 | // Test the request-challenge-retry sequence for basic auth, through |
| 8003 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8004 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8005 | HttpRequestInfo request; |
| 8006 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8007 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8008 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8009 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8010 | |
| 8011 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8012 | session_deps_.proxy_service = |
| 8013 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8014 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8015 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8017 | |
| 8018 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8019 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8020 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8021 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8022 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8023 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8025 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8026 | // be issuing -- the final header line contains the credentials. |
| 8027 | const char* const kAuthCredentials[] = { |
| 8028 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8029 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8030 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8031 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8032 | HostPortPair("www.example.org", 443))); |
| 8033 | // fetch https://www.example.org/ via HTTP |
| 8034 | const char get[] = |
| 8035 | "GET / HTTP/1.1\r\n" |
| 8036 | "Host: www.example.org\r\n" |
| 8037 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8038 | SpdySerializedFrame wrapped_get( |
| 8039 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8040 | |
| 8041 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8042 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8043 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8044 | }; |
| 8045 | |
| 8046 | // The proxy responds to the connect with a 407, using a persistent |
| 8047 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8048 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8049 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8050 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8051 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8052 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8053 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8054 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8055 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8056 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8057 | "Content-Length: 5\r\n\r\n"; |
| 8058 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8059 | SpdySerializedFrame wrapped_get_resp( |
| 8060 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8061 | SpdySerializedFrame wrapped_body( |
| 8062 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8063 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8064 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8065 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8066 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8067 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8068 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8069 | }; |
| 8070 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8071 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8072 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8073 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8074 | // Negotiate SPDY to the proxy |
| 8075 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8076 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8078 | // Vanilla SSL to the server |
| 8079 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8081 | |
| 8082 | TestCompletionCallback callback1; |
| 8083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8084 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8085 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8086 | |
| 8087 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8089 | |
| 8090 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8091 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8092 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8093 | log.GetEntries(&entries); |
| 8094 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8095 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8096 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8097 | ExpectLogContainsSomewhere( |
| 8098 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8099 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8100 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8101 | |
| 8102 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8103 | ASSERT_TRUE(response); |
| 8104 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8105 | EXPECT_EQ(407, response->headers->response_code()); |
| 8106 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8107 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8108 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8109 | |
| 8110 | TestCompletionCallback callback2; |
| 8111 | |
| 8112 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8113 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8115 | |
| 8116 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8118 | |
| 8119 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8120 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8121 | |
| 8122 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8123 | EXPECT_EQ(200, response->headers->response_code()); |
| 8124 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8125 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8126 | |
| 8127 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8128 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8129 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8130 | LoadTimingInfo load_timing_info; |
| 8131 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8132 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8133 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8134 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8135 | trans.reset(); |
| 8136 | session->CloseAllConnections(); |
| 8137 | } |
| 8138 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8139 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8140 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8141 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8142 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8143 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8144 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8145 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8146 | HttpRequestInfo request; |
| 8147 | HttpRequestInfo push_request; |
| 8148 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8150 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8151 | push_request.method = "GET"; |
| 8152 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8153 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8154 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8155 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8156 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8157 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8158 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8159 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8160 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8161 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8163 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8164 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8165 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8166 | SpdySerializedFrame stream2_priority( |
| 8167 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8168 | |
| 8169 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8170 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8171 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8172 | }; |
| 8173 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8174 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8175 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8176 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8177 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8178 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8179 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8180 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8181 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8182 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8183 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8184 | |
| 8185 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8186 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8187 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8188 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8189 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8190 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8191 | }; |
| 8192 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8193 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8194 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8195 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8196 | // Negotiate SPDY to the proxy |
| 8197 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8198 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8201 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8203 | TestCompletionCallback callback; |
| 8204 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8206 | |
| 8207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8211 | std::unique_ptr<HttpNetworkTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8212 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8213 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8215 | |
| 8216 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8218 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8219 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8220 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8221 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8222 | |
| 8223 | EXPECT_EQ(200, response->headers->response_code()); |
| 8224 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8225 | |
| 8226 | std::string response_data; |
| 8227 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8229 | EXPECT_EQ("hello!", response_data); |
| 8230 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8231 | LoadTimingInfo load_timing_info; |
| 8232 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8233 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8234 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8235 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8236 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8237 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8238 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8239 | |
| 8240 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8242 | EXPECT_EQ("pushed", response_data); |
| 8243 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8244 | LoadTimingInfo push_load_timing_info; |
| 8245 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8246 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8247 | // The transactions should share a socket ID, despite being for different |
| 8248 | // origins. |
| 8249 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8250 | push_load_timing_info.socket_log_id); |
| 8251 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8252 | trans.reset(); |
| 8253 | push_trans.reset(); |
| 8254 | session->CloseAllConnections(); |
| 8255 | } |
| 8256 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8257 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8258 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8259 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8260 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8261 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8262 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8263 | HttpRequestInfo request; |
| 8264 | |
| 8265 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8266 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8267 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8268 | session_deps_.proxy_service = |
| 8269 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8270 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8271 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8272 | |
| 8273 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8274 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8277 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8278 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8279 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8280 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8281 | SpdySerializedFrame push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8282 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8283 | |
| 8284 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8285 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8286 | }; |
| 8287 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8288 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8289 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8290 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8291 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8292 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8293 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8294 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8295 | |
| 8296 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8297 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8298 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8299 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8300 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8301 | }; |
| 8302 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8303 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8304 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8305 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8306 | // Negotiate SPDY to the proxy |
| 8307 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8308 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8309 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8311 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8312 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8313 | TestCompletionCallback callback; |
| 8314 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8316 | |
| 8317 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8319 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8320 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8321 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8322 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8323 | |
| 8324 | EXPECT_EQ(200, response->headers->response_code()); |
| 8325 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8326 | |
| 8327 | std::string response_data; |
| 8328 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8329 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8330 | EXPECT_EQ("hello!", response_data); |
| 8331 | |
| 8332 | trans.reset(); |
| 8333 | session->CloseAllConnections(); |
| 8334 | } |
| 8335 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8336 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8337 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8338 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8339 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8340 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8341 | proxy_delegate->set_trusted_spdy_proxy( |
| 8342 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8343 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8344 | HttpRequestInfo request; |
| 8345 | |
| 8346 | request.method = "GET"; |
| 8347 | request.url = GURL("http://www.example.org/"); |
| 8348 | |
| 8349 | // Configure against https proxy server "myproxy:70". |
| 8350 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8351 | BoundTestNetLog log; |
| 8352 | session_deps_.net_log = log.bound().net_log(); |
| 8353 | |
| 8354 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8355 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8358 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8359 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8360 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8361 | SpdySerializedFrame stream2_priority( |
| 8362 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8363 | |
| 8364 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8365 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8366 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8367 | }; |
| 8368 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8369 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8370 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8371 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8372 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8373 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8374 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8375 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8376 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8377 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8378 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8379 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8380 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8381 | |
| 8382 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8383 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8384 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame^] | 8385 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8386 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8387 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8388 | }; |
| 8389 | |
| 8390 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8391 | arraysize(spdy_writes)); |
| 8392 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8393 | // Negotiate SPDY to the proxy |
| 8394 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8395 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8398 | std::unique_ptr<HttpNetworkTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8400 | TestCompletionCallback callback; |
| 8401 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8403 | |
| 8404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8405 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8406 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8407 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8408 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8409 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8410 | |
| 8411 | EXPECT_EQ(200, response->headers->response_code()); |
| 8412 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8413 | |
| 8414 | std::string response_data; |
| 8415 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8416 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8417 | EXPECT_EQ("hello!", response_data); |
| 8418 | |
| 8419 | trans.reset(); |
| 8420 | session->CloseAllConnections(); |
| 8421 | } |
| 8422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8423 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8424 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8425 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8426 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8427 | |
| 8428 | HttpRequestInfo request; |
| 8429 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8430 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8431 | |
| 8432 | // Attempt to fetch the URL from a server with a bad cert |
| 8433 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8434 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8435 | "Host: www.example.org:443\r\n" |
| 8436 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8437 | }; |
| 8438 | |
| 8439 | MockRead bad_cert_reads[] = { |
| 8440 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8441 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8442 | }; |
| 8443 | |
| 8444 | // Attempt to fetch the URL with a good cert |
| 8445 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8446 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8447 | "Host: www.example.org:443\r\n" |
| 8448 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8449 | MockWrite("GET / HTTP/1.1\r\n" |
| 8450 | "Host: www.example.org\r\n" |
| 8451 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8452 | }; |
| 8453 | |
| 8454 | MockRead good_cert_reads[] = { |
| 8455 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8456 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8457 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8458 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8459 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8460 | }; |
| 8461 | |
| 8462 | StaticSocketDataProvider ssl_bad_certificate( |
| 8463 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8464 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8465 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8466 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8467 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8468 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8469 | |
| 8470 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8472 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8474 | |
| 8475 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8477 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8480 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8485 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8487 | |
| 8488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8489 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8491 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8493 | |
| 8494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8497 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8498 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8499 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8500 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8501 | } |
| 8502 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8503 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8504 | HttpRequestInfo request; |
| 8505 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8507 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8508 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8509 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8510 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8511 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8512 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8513 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8514 | MockWrite( |
| 8515 | "GET / HTTP/1.1\r\n" |
| 8516 | "Host: www.example.org\r\n" |
| 8517 | "Connection: keep-alive\r\n" |
| 8518 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8519 | }; |
| 8520 | |
| 8521 | // Lastly, the server responds with the actual content. |
| 8522 | MockRead data_reads[] = { |
| 8523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8527 | }; |
| 8528 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8529 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8530 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8531 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8533 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8534 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8535 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8536 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8537 | |
| 8538 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8539 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8540 | } |
| 8541 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8542 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8543 | HttpRequestInfo request; |
| 8544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8545 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8546 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8547 | "Chromium Ultra Awesome X Edition"); |
| 8548 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8549 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8552 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8553 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8554 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8555 | "Host: www.example.org:443\r\n" |
| 8556 | "Proxy-Connection: keep-alive\r\n" |
| 8557 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8558 | }; |
| 8559 | MockRead data_reads[] = { |
| 8560 | // Return an error, so the transaction stops here (this test isn't |
| 8561 | // interested in the rest). |
| 8562 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8563 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8564 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8565 | }; |
| 8566 | |
| 8567 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8568 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8569 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8571 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8573 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8575 | |
| 8576 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8578 | } |
| 8579 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8580 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8581 | HttpRequestInfo request; |
| 8582 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8583 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8584 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8585 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8589 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8590 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8591 | MockWrite( |
| 8592 | "GET / HTTP/1.1\r\n" |
| 8593 | "Host: www.example.org\r\n" |
| 8594 | "Connection: keep-alive\r\n" |
| 8595 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8596 | }; |
| 8597 | |
| 8598 | // Lastly, the server responds with the actual content. |
| 8599 | MockRead data_reads[] = { |
| 8600 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8601 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8602 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8603 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8604 | }; |
| 8605 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8606 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8607 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8610 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8611 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8612 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8614 | |
| 8615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8617 | } |
| 8618 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8619 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8620 | HttpRequestInfo request; |
| 8621 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8622 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8626 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8627 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8628 | MockWrite( |
| 8629 | "POST / HTTP/1.1\r\n" |
| 8630 | "Host: www.example.org\r\n" |
| 8631 | "Connection: keep-alive\r\n" |
| 8632 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8633 | }; |
| 8634 | |
| 8635 | // Lastly, the server responds with the actual content. |
| 8636 | MockRead data_reads[] = { |
| 8637 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8639 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8640 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8641 | }; |
| 8642 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8643 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8644 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8647 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8651 | |
| 8652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8654 | } |
| 8655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8656 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8657 | HttpRequestInfo request; |
| 8658 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8659 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8663 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8664 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8665 | MockWrite( |
| 8666 | "PUT / HTTP/1.1\r\n" |
| 8667 | "Host: www.example.org\r\n" |
| 8668 | "Connection: keep-alive\r\n" |
| 8669 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8670 | }; |
| 8671 | |
| 8672 | // Lastly, the server responds with the actual content. |
| 8673 | MockRead data_reads[] = { |
| 8674 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8675 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8676 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8677 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8678 | }; |
| 8679 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8681 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8684 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8686 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8688 | |
| 8689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8691 | } |
| 8692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8693 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8694 | HttpRequestInfo request; |
| 8695 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8696 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8697 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8699 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8700 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8701 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8702 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8703 | "Host: www.example.org\r\n" |
| 8704 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8705 | }; |
| 8706 | |
| 8707 | // Lastly, the server responds with the actual content. |
| 8708 | MockRead data_reads[] = { |
| 8709 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8710 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8711 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8712 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8713 | }; |
| 8714 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8715 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8716 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8717 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8719 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8720 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8721 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8723 | |
| 8724 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8725 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8726 | } |
| 8727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8728 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8729 | HttpRequestInfo request; |
| 8730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8731 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8732 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8736 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8737 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8738 | MockWrite( |
| 8739 | "GET / HTTP/1.1\r\n" |
| 8740 | "Host: www.example.org\r\n" |
| 8741 | "Connection: keep-alive\r\n" |
| 8742 | "Pragma: no-cache\r\n" |
| 8743 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8744 | }; |
| 8745 | |
| 8746 | // Lastly, the server responds with the actual content. |
| 8747 | MockRead data_reads[] = { |
| 8748 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8749 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8750 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8751 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8752 | }; |
| 8753 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8754 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8755 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8758 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8759 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8760 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8762 | |
| 8763 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8764 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8765 | } |
| 8766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8767 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8768 | HttpRequestInfo request; |
| 8769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8770 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8771 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8775 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8776 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8777 | MockWrite( |
| 8778 | "GET / HTTP/1.1\r\n" |
| 8779 | "Host: www.example.org\r\n" |
| 8780 | "Connection: keep-alive\r\n" |
| 8781 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8782 | }; |
| 8783 | |
| 8784 | // Lastly, the server responds with the actual content. |
| 8785 | MockRead data_reads[] = { |
| 8786 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8787 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8788 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | }; |
| 8791 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8792 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8793 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8794 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8796 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8800 | |
| 8801 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8803 | } |
| 8804 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8805 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8806 | HttpRequestInfo request; |
| 8807 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8808 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8809 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8810 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8813 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8814 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8815 | MockWrite( |
| 8816 | "GET / HTTP/1.1\r\n" |
| 8817 | "Host: www.example.org\r\n" |
| 8818 | "Connection: keep-alive\r\n" |
| 8819 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8820 | }; |
| 8821 | |
| 8822 | // Lastly, the server responds with the actual content. |
| 8823 | MockRead data_reads[] = { |
| 8824 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8825 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8826 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8827 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8828 | }; |
| 8829 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8831 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8834 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8836 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8838 | |
| 8839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8841 | } |
| 8842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8843 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8844 | HttpRequestInfo request; |
| 8845 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8846 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8847 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8848 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8849 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8850 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8853 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8854 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8855 | MockWrite( |
| 8856 | "GET / HTTP/1.1\r\n" |
| 8857 | "Host: www.example.org\r\n" |
| 8858 | "Connection: keep-alive\r\n" |
| 8859 | "referer: www.foo.com\r\n" |
| 8860 | "hEllo: Kitty\r\n" |
| 8861 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8862 | }; |
| 8863 | |
| 8864 | // Lastly, the server responds with the actual content. |
| 8865 | MockRead data_reads[] = { |
| 8866 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8867 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8868 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8869 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8870 | }; |
| 8871 | |
| 8872 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8873 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8874 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8876 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8877 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8878 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8880 | |
| 8881 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8882 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8883 | } |
| 8884 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8885 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8886 | HttpRequestInfo request; |
| 8887 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8888 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8889 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8890 | session_deps_.proxy_service = |
| 8891 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8892 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8893 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8897 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8898 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8899 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8900 | |
| 8901 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8902 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8903 | MockWrite( |
| 8904 | "GET / HTTP/1.1\r\n" |
| 8905 | "Host: www.example.org\r\n" |
| 8906 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8907 | |
| 8908 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8909 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8910 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8911 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8912 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8913 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8914 | }; |
| 8915 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8916 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8917 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8918 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8920 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8922 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8924 | |
| 8925 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8929 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8930 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8931 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8932 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8933 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8934 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8935 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8936 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8937 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8938 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8939 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8940 | EXPECT_EQ("Payload", response_text); |
| 8941 | } |
| 8942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8943 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8944 | HttpRequestInfo request; |
| 8945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8946 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8947 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8948 | session_deps_.proxy_service = |
| 8949 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8950 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8951 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8952 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8953 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8954 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8955 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8956 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8957 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8958 | |
| 8959 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8960 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8961 | arraysize(write_buffer)), |
| 8962 | MockWrite( |
| 8963 | "GET / HTTP/1.1\r\n" |
| 8964 | "Host: www.example.org\r\n" |
| 8965 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8966 | |
| 8967 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8968 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8969 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8970 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8971 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8972 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8973 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8974 | }; |
| 8975 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8977 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8979 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8980 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8983 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8984 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8985 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8987 | |
| 8988 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8990 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8991 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8992 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8993 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8994 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8997 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8998 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8999 | |
| 9000 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9001 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9002 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9003 | EXPECT_EQ("Payload", response_text); |
| 9004 | } |
| 9005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9006 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9007 | HttpRequestInfo request; |
| 9008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9009 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9010 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9011 | session_deps_.proxy_service = |
| 9012 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9013 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9014 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9015 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9017 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9018 | |
| 9019 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9020 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9021 | |
| 9022 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9023 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9024 | MockWrite( |
| 9025 | "GET / HTTP/1.1\r\n" |
| 9026 | "Host: www.example.org\r\n" |
| 9027 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9028 | |
| 9029 | MockRead data_reads[] = { |
| 9030 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9031 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9032 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9033 | MockRead("Payload"), |
| 9034 | MockRead(SYNCHRONOUS, OK) |
| 9035 | }; |
| 9036 | |
| 9037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9038 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9040 | |
| 9041 | TestCompletionCallback callback; |
| 9042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9045 | |
| 9046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9050 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9051 | |
| 9052 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9053 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9054 | TestLoadTimingNotReused(load_timing_info, |
| 9055 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9056 | |
| 9057 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9058 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9060 | EXPECT_EQ("Payload", response_text); |
| 9061 | } |
| 9062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9063 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9064 | HttpRequestInfo request; |
| 9065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9066 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9067 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9068 | session_deps_.proxy_service = |
| 9069 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9070 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9071 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9075 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9076 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9077 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9078 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9079 | 0x05, // Version |
| 9080 | 0x01, // Command (CONNECT) |
| 9081 | 0x00, // Reserved. |
| 9082 | 0x03, // Address type (DOMAINNAME). |
| 9083 | 0x0F, // Length of domain (15) |
| 9084 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9085 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9086 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9087 | const char kSOCKS5OkResponse[] = |
| 9088 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9089 | |
| 9090 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9091 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9092 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9093 | MockWrite( |
| 9094 | "GET / HTTP/1.1\r\n" |
| 9095 | "Host: www.example.org\r\n" |
| 9096 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9097 | |
| 9098 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9099 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9100 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9101 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9102 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9103 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9104 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9105 | }; |
| 9106 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9108 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9111 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9113 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9115 | |
| 9116 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9119 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9120 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9121 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9122 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9123 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9124 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9125 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9126 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9127 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9128 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9131 | EXPECT_EQ("Payload", response_text); |
| 9132 | } |
| 9133 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9134 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9135 | HttpRequestInfo request; |
| 9136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9137 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9138 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9139 | session_deps_.proxy_service = |
| 9140 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9141 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9142 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9146 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9147 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9148 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9149 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9150 | 0x05, // Version |
| 9151 | 0x01, // Command (CONNECT) |
| 9152 | 0x00, // Reserved. |
| 9153 | 0x03, // Address type (DOMAINNAME). |
| 9154 | 0x0F, // Length of domain (15) |
| 9155 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9156 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9157 | }; |
| 9158 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9159 | const char kSOCKS5OkResponse[] = |
| 9160 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9161 | |
| 9162 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9163 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9164 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9165 | arraysize(kSOCKS5OkRequest)), |
| 9166 | MockWrite( |
| 9167 | "GET / HTTP/1.1\r\n" |
| 9168 | "Host: www.example.org\r\n" |
| 9169 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9170 | |
| 9171 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9172 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9173 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9174 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9175 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9176 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9177 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9178 | }; |
| 9179 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9180 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9181 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9182 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9183 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9184 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9185 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9187 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9188 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9189 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9190 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9191 | |
| 9192 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9193 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9195 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9196 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9197 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9198 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9199 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9200 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9201 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9202 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9203 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9204 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9205 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9207 | EXPECT_EQ("Payload", response_text); |
| 9208 | } |
| 9209 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9210 | namespace { |
| 9211 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9212 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9213 | |
| 9214 | struct GroupNameTest { |
| 9215 | std::string proxy_server; |
| 9216 | std::string url; |
| 9217 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9218 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9219 | }; |
| 9220 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9221 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9222 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9223 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9224 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9225 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9226 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9227 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9228 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9229 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9230 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9231 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9232 | |
| 9233 | return session; |
| 9234 | } |
| 9235 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9236 | int GroupNameTransactionHelper(const std::string& url, |
| 9237 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9238 | HttpRequestInfo request; |
| 9239 | request.method = "GET"; |
| 9240 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9242 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9244 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9245 | |
| 9246 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9247 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9248 | } |
| 9249 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9250 | } // namespace |
| 9251 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9252 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9253 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9254 | { |
| 9255 | "", // unused |
| 9256 | "http://www.example.org/direct", |
| 9257 | "www.example.org:80", |
| 9258 | false, |
| 9259 | }, |
| 9260 | { |
| 9261 | "", // unused |
| 9262 | "http://[2001:1418:13:1::25]/direct", |
| 9263 | "[2001:1418:13:1::25]:80", |
| 9264 | false, |
| 9265 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9266 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9267 | // SSL Tests |
| 9268 | { |
| 9269 | "", // unused |
| 9270 | "https://www.example.org/direct_ssl", |
| 9271 | "ssl/www.example.org:443", |
| 9272 | true, |
| 9273 | }, |
| 9274 | { |
| 9275 | "", // unused |
| 9276 | "https://[2001:1418:13:1::25]/direct", |
| 9277 | "ssl/[2001:1418:13:1::25]:443", |
| 9278 | true, |
| 9279 | }, |
| 9280 | { |
| 9281 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9282 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9283 | "ssl/host.with.alternate:443", |
| 9284 | true, |
| 9285 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9286 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9287 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9288 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9289 | session_deps_.proxy_service = |
| 9290 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9291 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9292 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9293 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9294 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9295 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9296 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9297 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9298 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9299 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9300 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9301 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9302 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9303 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9304 | |
| 9305 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9306 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9307 | if (tests[i].ssl) |
| 9308 | EXPECT_EQ(tests[i].expected_group_name, |
| 9309 | ssl_conn_pool->last_group_name_received()); |
| 9310 | else |
| 9311 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9312 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9313 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9314 | } |
| 9315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9316 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9317 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9318 | { |
| 9319 | "http_proxy", |
| 9320 | "http://www.example.org/http_proxy_normal", |
| 9321 | "www.example.org:80", |
| 9322 | false, |
| 9323 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9324 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9325 | // SSL Tests |
| 9326 | { |
| 9327 | "http_proxy", |
| 9328 | "https://www.example.org/http_connect_ssl", |
| 9329 | "ssl/www.example.org:443", |
| 9330 | true, |
| 9331 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9332 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9333 | { |
| 9334 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9335 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9336 | "ssl/host.with.alternate:443", |
| 9337 | true, |
| 9338 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9339 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9340 | { |
| 9341 | "http_proxy", |
| 9342 | "ftp://ftp.google.com/http_proxy_normal", |
| 9343 | "ftp/ftp.google.com:21", |
| 9344 | false, |
| 9345 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9346 | }; |
| 9347 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9348 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9349 | session_deps_.proxy_service = |
| 9350 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9351 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9352 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9353 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9354 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9355 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9356 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9357 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9358 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9359 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9360 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9361 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9362 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9363 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9364 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9365 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9366 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9367 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9368 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9369 | |
| 9370 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9371 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9372 | if (tests[i].ssl) |
| 9373 | EXPECT_EQ(tests[i].expected_group_name, |
| 9374 | ssl_conn_pool->last_group_name_received()); |
| 9375 | else |
| 9376 | EXPECT_EQ(tests[i].expected_group_name, |
| 9377 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9378 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9379 | } |
| 9380 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9381 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9382 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9383 | { |
| 9384 | "socks4://socks_proxy:1080", |
| 9385 | "http://www.example.org/socks4_direct", |
| 9386 | "socks4/www.example.org:80", |
| 9387 | false, |
| 9388 | }, |
| 9389 | { |
| 9390 | "socks5://socks_proxy:1080", |
| 9391 | "http://www.example.org/socks5_direct", |
| 9392 | "socks5/www.example.org:80", |
| 9393 | false, |
| 9394 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9395 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9396 | // SSL Tests |
| 9397 | { |
| 9398 | "socks4://socks_proxy:1080", |
| 9399 | "https://www.example.org/socks4_ssl", |
| 9400 | "socks4/ssl/www.example.org:443", |
| 9401 | true, |
| 9402 | }, |
| 9403 | { |
| 9404 | "socks5://socks_proxy:1080", |
| 9405 | "https://www.example.org/socks5_ssl", |
| 9406 | "socks5/ssl/www.example.org:443", |
| 9407 | true, |
| 9408 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9409 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9410 | { |
| 9411 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9412 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9413 | "socks4/ssl/host.with.alternate:443", |
| 9414 | true, |
| 9415 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9416 | }; |
| 9417 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9418 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9419 | session_deps_.proxy_service = |
| 9420 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9421 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9422 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9423 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9424 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9425 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9426 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9427 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9428 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9429 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9430 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9431 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9432 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9433 | new MockClientSocketPoolManager); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9434 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9435 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9436 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9437 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9438 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9441 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9442 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9443 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9444 | if (tests[i].ssl) |
| 9445 | EXPECT_EQ(tests[i].expected_group_name, |
| 9446 | ssl_conn_pool->last_group_name_received()); |
| 9447 | else |
| 9448 | EXPECT_EQ(tests[i].expected_group_name, |
| 9449 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9450 | } |
| 9451 | } |
| 9452 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9453 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9454 | HttpRequestInfo request; |
| 9455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9456 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9457 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9458 | session_deps_.proxy_service = |
| 9459 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9460 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9461 | // This simulates failure resolving all hostnames; that means we will fail |
| 9462 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9463 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9464 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9468 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9470 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9472 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9473 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9474 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9475 | } |
| 9476 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9477 | // Base test to make sure that when the load flags for a request specify to |
| 9478 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9479 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9480 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9481 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9482 | HttpRequestInfo request_info; |
| 9483 | request_info.method = "GET"; |
| 9484 | request_info.load_flags = load_flags; |
| 9485 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9486 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9487 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9488 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9492 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9493 | // 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] | 9494 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9495 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9496 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9497 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9498 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9499 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9500 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9501 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9502 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9503 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9504 | |
| 9505 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9506 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9507 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9508 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9509 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9510 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9511 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9512 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9513 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9514 | // 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] | 9515 | // we can tell if the next lookup hit the cache, or the "network". |
| 9516 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9517 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9518 | |
| 9519 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9520 | // 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] | 9521 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9522 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9523 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9524 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9525 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9526 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9527 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9528 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9529 | |
| 9530 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9531 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9532 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9533 | } |
| 9534 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9535 | // There are multiple load flags that should trigger the host cache bypass. |
| 9536 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9537 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9538 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9539 | } |
| 9540 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9541 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9542 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9543 | } |
| 9544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9545 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9546 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9547 | } |
| 9548 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9549 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9550 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9551 | HttpRequestInfo request; |
| 9552 | request.method = "GET"; |
| 9553 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9554 | |
| 9555 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9556 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9557 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9558 | StaticSocketDataProvider data(NULL, 0, |
| 9559 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9563 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9564 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9565 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9566 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9567 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9569 | |
| 9570 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9571 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9572 | |
| 9573 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9574 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9575 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9576 | } |
| 9577 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9578 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9579 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9580 | HttpRequestInfo request; |
| 9581 | request.method = "GET"; |
| 9582 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9583 | |
| 9584 | MockRead data_reads[] = { |
| 9585 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9586 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9587 | }; |
| 9588 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9589 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9590 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9593 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9596 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9597 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9599 | |
| 9600 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9601 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9604 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9605 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9606 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9607 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9608 | |
| 9609 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9610 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9611 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9612 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9613 | |
| 9614 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9615 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9616 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9617 | } |
| 9618 | |
| 9619 | // Make sure that a dropped connection while draining the body for auth |
| 9620 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9621 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9622 | HttpRequestInfo request; |
| 9623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9624 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9625 | |
| 9626 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9627 | MockWrite( |
| 9628 | "GET / HTTP/1.1\r\n" |
| 9629 | "Host: www.example.org\r\n" |
| 9630 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9631 | }; |
| 9632 | |
| 9633 | MockRead data_reads1[] = { |
| 9634 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9635 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9636 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9637 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9638 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9639 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9640 | }; |
| 9641 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9642 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9643 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9646 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9647 | // be issuing -- the final header line contains the credentials. |
| 9648 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9649 | MockWrite( |
| 9650 | "GET / HTTP/1.1\r\n" |
| 9651 | "Host: www.example.org\r\n" |
| 9652 | "Connection: keep-alive\r\n" |
| 9653 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9654 | }; |
| 9655 | |
| 9656 | // Lastly, the server responds with the actual content. |
| 9657 | MockRead data_reads2[] = { |
| 9658 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9659 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9660 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9661 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9662 | }; |
| 9663 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9664 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9665 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9666 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9669 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9673 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9675 | |
| 9676 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9677 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9679 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9680 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9681 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9683 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9685 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9687 | |
| 9688 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9689 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9691 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9692 | ASSERT_TRUE(response); |
| 9693 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9694 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9695 | } |
| 9696 | |
| 9697 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9698 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9699 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9700 | |
| 9701 | HttpRequestInfo request; |
| 9702 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9703 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9704 | |
| 9705 | MockRead proxy_reads[] = { |
| 9706 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9707 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9708 | }; |
| 9709 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9710 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9711 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9712 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9716 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9717 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9718 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9725 | |
| 9726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9727 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9728 | } |
| 9729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9730 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9731 | HttpRequestInfo request; |
| 9732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9737 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9738 | MockRead data_reads[] = { |
| 9739 | 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] | 9740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9741 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9742 | |
| 9743 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9744 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9746 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9747 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9748 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9750 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9751 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9753 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9754 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9755 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9756 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9757 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9758 | |
| 9759 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9760 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9761 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9762 | } |
| 9763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9764 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9765 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9766 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9767 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9768 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9769 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9770 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9771 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9772 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9773 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9774 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9775 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9776 | |
| 9777 | HttpRequestInfo request; |
| 9778 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9779 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9780 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9784 | |
| 9785 | MockRead data_reads[] = { |
| 9786 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9787 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9789 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9790 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9793 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9797 | |
| 9798 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9799 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9801 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9802 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9803 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9804 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9805 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9806 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9807 | } |
| 9808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9809 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9810 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9811 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9812 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9813 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9814 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9815 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9816 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9817 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9818 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9819 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9820 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9821 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9822 | |
| 9823 | HttpRequestInfo request; |
| 9824 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9825 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9826 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9827 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9828 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9831 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9832 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9833 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9835 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9837 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9839 | |
| 9840 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9841 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9842 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9843 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9844 | } |
| 9845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9846 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9847 | class FakeUploadElementReader : public UploadElementReader { |
| 9848 | public: |
| 9849 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9850 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9851 | |
| 9852 | const CompletionCallback& callback() const { return callback_; } |
| 9853 | |
| 9854 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9855 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9856 | callback_ = callback; |
| 9857 | return ERR_IO_PENDING; |
| 9858 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9859 | uint64_t GetContentLength() const override { return 0; } |
| 9860 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9861 | int Read(IOBuffer* buf, |
| 9862 | int buf_length, |
| 9863 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9864 | return ERR_FAILED; |
| 9865 | } |
| 9866 | |
| 9867 | private: |
| 9868 | CompletionCallback callback_; |
| 9869 | }; |
| 9870 | |
| 9871 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9872 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9873 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9874 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9875 | |
| 9876 | HttpRequestInfo request; |
| 9877 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9878 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9879 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9880 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9882 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9883 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9884 | |
| 9885 | StaticSocketDataProvider data; |
| 9886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9887 | |
| 9888 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9889 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9891 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9892 | |
| 9893 | // Transaction is pending on request body initialization. |
| 9894 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9895 | |
| 9896 | // Return Init()'s result after the transaction gets destroyed. |
| 9897 | trans.reset(); |
| 9898 | fake_reader->callback().Run(OK); // Should not crash. |
| 9899 | } |
| 9900 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9901 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9902 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9903 | HttpRequestInfo request; |
| 9904 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9905 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9906 | |
| 9907 | // First transaction will request a resource and receive a Basic challenge |
| 9908 | // with realm="first_realm". |
| 9909 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9910 | MockWrite( |
| 9911 | "GET / HTTP/1.1\r\n" |
| 9912 | "Host: www.example.org\r\n" |
| 9913 | "Connection: keep-alive\r\n" |
| 9914 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9915 | }; |
| 9916 | MockRead data_reads1[] = { |
| 9917 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9918 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9919 | "\r\n"), |
| 9920 | }; |
| 9921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9922 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9923 | // for first_realm. The server will reject and provide a challenge with |
| 9924 | // second_realm. |
| 9925 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9926 | MockWrite( |
| 9927 | "GET / HTTP/1.1\r\n" |
| 9928 | "Host: www.example.org\r\n" |
| 9929 | "Connection: keep-alive\r\n" |
| 9930 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9931 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9932 | }; |
| 9933 | MockRead data_reads2[] = { |
| 9934 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9935 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9936 | "\r\n"), |
| 9937 | }; |
| 9938 | |
| 9939 | // This again fails, and goes back to first_realm. Make sure that the |
| 9940 | // entry is removed from cache. |
| 9941 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9942 | MockWrite( |
| 9943 | "GET / HTTP/1.1\r\n" |
| 9944 | "Host: www.example.org\r\n" |
| 9945 | "Connection: keep-alive\r\n" |
| 9946 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9947 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9948 | }; |
| 9949 | MockRead data_reads3[] = { |
| 9950 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9951 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9952 | "\r\n"), |
| 9953 | }; |
| 9954 | |
| 9955 | // Try one last time (with the correct password) and get the resource. |
| 9956 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9957 | MockWrite( |
| 9958 | "GET / HTTP/1.1\r\n" |
| 9959 | "Host: www.example.org\r\n" |
| 9960 | "Connection: keep-alive\r\n" |
| 9961 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9962 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9963 | }; |
| 9964 | MockRead data_reads4[] = { |
| 9965 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9966 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9967 | "Content-Length: 5\r\n" |
| 9968 | "\r\n" |
| 9969 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9970 | }; |
| 9971 | |
| 9972 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9973 | data_writes1, arraysize(data_writes1)); |
| 9974 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9975 | data_writes2, arraysize(data_writes2)); |
| 9976 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9977 | data_writes3, arraysize(data_writes3)); |
| 9978 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9979 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9980 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9981 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9982 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9983 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9985 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9989 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9990 | // Issue the first request with Authorize headers. There should be a |
| 9991 | // password prompt for first_realm waiting to be filled in after the |
| 9992 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9993 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9995 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9997 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9998 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9999 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10000 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10001 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10002 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10003 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10004 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10005 | |
| 10006 | // Issue the second request with an incorrect password. There should be a |
| 10007 | // password prompt for second_realm waiting to be filled in after the |
| 10008 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10009 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10010 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10011 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10013 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10014 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10015 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10016 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10017 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10018 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10019 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10020 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10021 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10022 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10023 | |
| 10024 | // Issue the third request with another incorrect password. There should be |
| 10025 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10026 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10027 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10028 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10029 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10030 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10032 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10033 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10034 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10035 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10036 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10037 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10038 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10039 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10040 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10041 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10042 | |
| 10043 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10044 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10045 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10046 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10047 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10048 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10049 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10050 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10051 | ASSERT_TRUE(response); |
| 10052 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10053 | } |
| 10054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10055 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10056 | MockRead data_reads[] = { |
| 10057 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10058 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10059 | MockRead("\r\n"), |
| 10060 | MockRead("hello world"), |
| 10061 | MockRead(SYNCHRONOUS, OK), |
| 10062 | }; |
| 10063 | |
| 10064 | HttpRequestInfo request; |
| 10065 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10066 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10067 | |
| 10068 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10069 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10070 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10071 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10073 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10074 | TestCompletionCallback callback; |
| 10075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10079 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10081 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10082 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10083 | HttpServerProperties* http_server_properties = |
| 10084 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10085 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10086 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10087 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10088 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10089 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10091 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10092 | ASSERT_TRUE(response); |
| 10093 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10094 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10095 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10096 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10097 | |
| 10098 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10099 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10100 | EXPECT_EQ("hello world", response_data); |
| 10101 | |
| 10102 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10103 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10104 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10105 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10106 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10107 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10108 | } |
| 10109 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10110 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10111 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10112 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10113 | MockRead data_reads[] = { |
| 10114 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10115 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10116 | MockRead("\r\n"), |
| 10117 | MockRead("hello world"), |
| 10118 | MockRead(SYNCHRONOUS, OK), |
| 10119 | }; |
| 10120 | |
| 10121 | HttpRequestInfo request; |
| 10122 | request.method = "GET"; |
| 10123 | request.url = GURL("http://www.example.org/"); |
| 10124 | request.load_flags = 0; |
| 10125 | |
| 10126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10128 | |
| 10129 | TestCompletionCallback callback; |
| 10130 | |
| 10131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10133 | |
| 10134 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10135 | HttpServerProperties* http_server_properties = |
| 10136 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10137 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10138 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10139 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10140 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10141 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10143 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10145 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10146 | ASSERT_TRUE(response); |
| 10147 | ASSERT_TRUE(response->headers); |
| 10148 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10149 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10150 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10151 | |
| 10152 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10153 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10154 | EXPECT_EQ("hello world", response_data); |
| 10155 | |
| 10156 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10157 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10158 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10159 | } |
| 10160 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10161 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 10162 | // hostname is different from that of origin. |
| 10163 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10164 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10165 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10166 | session_deps_.enable_http2_alternative_service_with_different_host = false; |
| 10167 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10168 | HttpRequestInfo request; |
| 10169 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10170 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10171 | request.load_flags = 0; |
| 10172 | |
| 10173 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10174 | StaticSocketDataProvider first_data; |
| 10175 | first_data.set_connect_data(mock_connect); |
| 10176 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10177 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10178 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10179 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10180 | |
| 10181 | MockRead data_reads[] = { |
| 10182 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10183 | MockRead(ASYNC, OK), |
| 10184 | }; |
| 10185 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10186 | 0); |
| 10187 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10188 | |
| 10189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10190 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10191 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10192 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10193 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10194 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10195 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10196 | http_server_properties->SetAlternativeService( |
| 10197 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10199 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10200 | TestCompletionCallback callback; |
| 10201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10202 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10203 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10204 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10205 | } |
| 10206 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10207 | // Regression test for https://crbug.com/615497: |
| 10208 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10209 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10210 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10211 | HttpRequestInfo request; |
| 10212 | request.method = "GET"; |
| 10213 | request.url = GURL("http://www.example.org/"); |
| 10214 | request.load_flags = 0; |
| 10215 | |
| 10216 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10217 | StaticSocketDataProvider first_data; |
| 10218 | first_data.set_connect_data(mock_connect); |
| 10219 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10220 | |
| 10221 | MockRead data_reads[] = { |
| 10222 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10223 | MockRead(ASYNC, OK), |
| 10224 | }; |
| 10225 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10226 | 0); |
| 10227 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10228 | |
| 10229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10230 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10231 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10232 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10233 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10234 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10235 | http_server_properties->SetAlternativeService( |
| 10236 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10238 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10239 | TestCompletionCallback callback; |
| 10240 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10241 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10242 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10243 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10244 | } |
| 10245 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10246 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10247 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10249 | HttpServerProperties* http_server_properties = |
| 10250 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10251 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10252 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10253 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10254 | http_server_properties->SetAlternativeService( |
| 10255 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10256 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10257 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10258 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10259 | |
| 10260 | // Send a clear header. |
| 10261 | MockRead data_reads[] = { |
| 10262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10263 | MockRead("Alt-Svc: clear\r\n"), |
| 10264 | MockRead("\r\n"), |
| 10265 | MockRead("hello world"), |
| 10266 | MockRead(SYNCHRONOUS, OK), |
| 10267 | }; |
| 10268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10270 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10271 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10273 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10274 | HttpRequestInfo request; |
| 10275 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10276 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10277 | |
| 10278 | TestCompletionCallback callback; |
| 10279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10281 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10282 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10283 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10285 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10286 | ASSERT_TRUE(response); |
| 10287 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10288 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10289 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10290 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10291 | |
| 10292 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10293 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10294 | EXPECT_EQ("hello world", response_data); |
| 10295 | |
| 10296 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10297 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10298 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10299 | } |
| 10300 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10301 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10302 | MockRead data_reads[] = { |
| 10303 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10304 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10305 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10306 | MockRead("hello world"), |
| 10307 | MockRead(SYNCHRONOUS, OK), |
| 10308 | }; |
| 10309 | |
| 10310 | HttpRequestInfo request; |
| 10311 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10312 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10313 | |
| 10314 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10315 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10316 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10317 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10319 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10320 | TestCompletionCallback callback; |
| 10321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10322 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10323 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10324 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10325 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10326 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10327 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10328 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10329 | HttpServerProperties* http_server_properties = |
| 10330 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10331 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10332 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10333 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10334 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10335 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10336 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10337 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10338 | ASSERT_TRUE(response); |
| 10339 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10340 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10341 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10342 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10343 | |
| 10344 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10345 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10346 | EXPECT_EQ("hello world", response_data); |
| 10347 | |
| 10348 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10349 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10350 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10351 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[0].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10352 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10353 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10354 | EXPECT_EQ(kProtoHTTP2, alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10355 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10356 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10357 | } |
| 10358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10359 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10360 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10361 | HostPortPair alternative("alternative.example.org", 443); |
| 10362 | std::string origin_url = "https://origin.example.org:443"; |
| 10363 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10364 | |
| 10365 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10366 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10367 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10369 | |
| 10370 | // HTTP/1.1 data for request. |
| 10371 | MockWrite http_writes[] = { |
| 10372 | MockWrite("GET / HTTP/1.1\r\n" |
| 10373 | "Host: alternative.example.org\r\n" |
| 10374 | "Connection: keep-alive\r\n\r\n"), |
| 10375 | }; |
| 10376 | |
| 10377 | MockRead http_reads[] = { |
| 10378 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10379 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10380 | "Content-Length: 40\r\n\r\n" |
| 10381 | "first HTTP/1.1 response from alternative"), |
| 10382 | }; |
| 10383 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10384 | http_writes, arraysize(http_writes)); |
| 10385 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10386 | |
| 10387 | StaticSocketDataProvider data_refused; |
| 10388 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10389 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10390 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10391 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10393 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10394 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10395 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10396 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10397 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10398 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10399 | // Mark the QUIC alternative service as broken. |
| 10400 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10401 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10402 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10404 | request.method = "GET"; |
| 10405 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10406 | TestCompletionCallback callback; |
| 10407 | NetErrorDetails details; |
| 10408 | EXPECT_FALSE(details.quic_broken); |
| 10409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10410 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10411 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10412 | EXPECT_TRUE(details.quic_broken); |
| 10413 | } |
| 10414 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10415 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10416 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10417 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10418 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10419 | std::string origin_url = "https://origin.example.org:443"; |
| 10420 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10421 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10422 | |
| 10423 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10424 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10425 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10427 | |
| 10428 | // HTTP/1.1 data for request. |
| 10429 | MockWrite http_writes[] = { |
| 10430 | MockWrite("GET / HTTP/1.1\r\n" |
| 10431 | "Host: alternative1.example.org\r\n" |
| 10432 | "Connection: keep-alive\r\n\r\n"), |
| 10433 | }; |
| 10434 | |
| 10435 | MockRead http_reads[] = { |
| 10436 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10437 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10438 | "Content-Length: 40\r\n\r\n" |
| 10439 | "first HTTP/1.1 response from alternative1"), |
| 10440 | }; |
| 10441 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10442 | http_writes, arraysize(http_writes)); |
| 10443 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10444 | |
| 10445 | StaticSocketDataProvider data_refused; |
| 10446 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10447 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10448 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10450 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10451 | session->http_server_properties(); |
| 10452 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10453 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10454 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10455 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10456 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10457 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10458 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10459 | expiration); |
| 10460 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10461 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10462 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10463 | expiration); |
| 10464 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10465 | |
| 10466 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10467 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10468 | |
| 10469 | // Mark one of the QUIC alternative service as broken. |
| 10470 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10471 | |
| 10472 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10473 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10474 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10475 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10477 | request.method = "GET"; |
| 10478 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10479 | TestCompletionCallback callback; |
| 10480 | NetErrorDetails details; |
| 10481 | EXPECT_FALSE(details.quic_broken); |
| 10482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10483 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10484 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10485 | EXPECT_FALSE(details.quic_broken); |
| 10486 | } |
| 10487 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10488 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10489 | HttpRequestInfo request; |
| 10490 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10491 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10492 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10493 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10494 | StaticSocketDataProvider first_data; |
| 10495 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10496 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10497 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10498 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10500 | |
| 10501 | MockRead data_reads[] = { |
| 10502 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10503 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10504 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10505 | }; |
| 10506 | StaticSocketDataProvider second_data( |
| 10507 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10508 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10509 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10510 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10511 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10512 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10513 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10514 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10515 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10516 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10517 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10518 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10519 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10520 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10521 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10522 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10525 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10526 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10527 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10529 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10531 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10532 | ASSERT_TRUE(response); |
| 10533 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10534 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10535 | |
| 10536 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10537 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10538 | EXPECT_EQ("hello world", response_data); |
| 10539 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10540 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10541 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10542 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10543 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10544 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10545 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10546 | } |
| 10547 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10548 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10549 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10550 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10551 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10552 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10553 | HttpRequestInfo restricted_port_request; |
| 10554 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10555 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | restricted_port_request.load_flags = 0; |
| 10557 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10558 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10559 | StaticSocketDataProvider first_data; |
| 10560 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10561 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10562 | |
| 10563 | MockRead data_reads[] = { |
| 10564 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10565 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10566 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10567 | }; |
| 10568 | StaticSocketDataProvider second_data( |
| 10569 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10570 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10571 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10572 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10573 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10574 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10576 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10577 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10578 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10579 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10580 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10581 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10582 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10583 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10584 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10585 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10588 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10589 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10590 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10591 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10593 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10594 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10595 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10596 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10597 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10598 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10599 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10600 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10601 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10602 | |
| 10603 | HttpRequestInfo restricted_port_request; |
| 10604 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10605 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10606 | restricted_port_request.load_flags = 0; |
| 10607 | |
| 10608 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10609 | StaticSocketDataProvider first_data; |
| 10610 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10611 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10612 | |
| 10613 | MockRead data_reads[] = { |
| 10614 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10615 | MockRead("hello world"), |
| 10616 | MockRead(ASYNC, OK), |
| 10617 | }; |
| 10618 | StaticSocketDataProvider second_data( |
| 10619 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10620 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10621 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10622 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10626 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10627 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10628 | session->http_server_properties(); |
| 10629 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10630 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10631 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10632 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10633 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10634 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10635 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10638 | TestCompletionCallback callback; |
| 10639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10640 | EXPECT_EQ(ERR_IO_PENDING, |
| 10641 | trans.Start(&restricted_port_request, callback.callback(), |
| 10642 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10643 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10644 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10645 | } |
| 10646 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10647 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10648 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10649 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10650 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10651 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10652 | HttpRequestInfo restricted_port_request; |
| 10653 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10654 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10655 | restricted_port_request.load_flags = 0; |
| 10656 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10657 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10658 | StaticSocketDataProvider first_data; |
| 10659 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10660 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10661 | |
| 10662 | MockRead data_reads[] = { |
| 10663 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10664 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10665 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10666 | }; |
| 10667 | StaticSocketDataProvider second_data( |
| 10668 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10669 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10670 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10671 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10675 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10676 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10677 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10678 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10679 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10680 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10681 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10682 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10683 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10684 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10685 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10687 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10689 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10690 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10692 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10693 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10694 | } |
| 10695 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10696 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10697 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10698 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10699 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10700 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10701 | HttpRequestInfo unrestricted_port_request; |
| 10702 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10703 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10704 | unrestricted_port_request.load_flags = 0; |
| 10705 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10706 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10707 | StaticSocketDataProvider first_data; |
| 10708 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10709 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10710 | |
| 10711 | MockRead data_reads[] = { |
| 10712 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10713 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10714 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10715 | }; |
| 10716 | StaticSocketDataProvider second_data( |
| 10717 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10718 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10719 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10720 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10724 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10725 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10726 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10727 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10728 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10729 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10730 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10731 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10732 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10733 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10736 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10738 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10739 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10741 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10742 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10743 | } |
| 10744 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10745 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10746 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10747 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10748 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10749 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10750 | HttpRequestInfo unrestricted_port_request; |
| 10751 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10752 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | unrestricted_port_request.load_flags = 0; |
| 10754 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10755 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10756 | StaticSocketDataProvider first_data; |
| 10757 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10758 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10759 | |
| 10760 | MockRead data_reads[] = { |
| 10761 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10762 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10763 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10764 | }; |
| 10765 | StaticSocketDataProvider second_data( |
| 10766 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10767 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10768 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10769 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10773 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10774 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10775 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10776 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10777 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10778 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10779 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10780 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10781 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10782 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10785 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10787 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10788 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10790 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10791 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10792 | } |
| 10793 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10794 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10795 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10796 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10797 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10798 | HttpRequestInfo request; |
| 10799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10800 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10801 | |
| 10802 | // The alternate protocol request will error out before we attempt to connect, |
| 10803 | // so only the standard HTTP request will try to connect. |
| 10804 | MockRead data_reads[] = { |
| 10805 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10806 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10807 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10808 | }; |
| 10809 | StaticSocketDataProvider data( |
| 10810 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10811 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10814 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10815 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10816 | session->http_server_properties(); |
| 10817 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10818 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10819 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10820 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10821 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10822 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10825 | TestCompletionCallback callback; |
| 10826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10829 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10830 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10832 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10833 | ASSERT_TRUE(response); |
| 10834 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10835 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10836 | |
| 10837 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10838 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10839 | EXPECT_EQ("hello world", response_data); |
| 10840 | } |
| 10841 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10842 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10843 | HttpRequestInfo request; |
| 10844 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10845 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10846 | |
| 10847 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10848 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10849 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10850 | MockRead("\r\n"), |
| 10851 | MockRead("hello world"), |
| 10852 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10853 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10854 | |
| 10855 | StaticSocketDataProvider first_transaction( |
| 10856 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10857 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10858 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10859 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10861 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10862 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10863 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10864 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10865 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10866 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10867 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10868 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10869 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10870 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10871 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10872 | }; |
| 10873 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10874 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10875 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10876 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10877 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10878 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10879 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10880 | NULL, 0, NULL, 0); |
| 10881 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10882 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10883 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10884 | &hanging_non_alternate_protocol_socket); |
| 10885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10886 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10889 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10892 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10894 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10895 | |
| 10896 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10897 | ASSERT_TRUE(response); |
| 10898 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10899 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10900 | |
| 10901 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10902 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10903 | EXPECT_EQ("hello world", response_data); |
| 10904 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10905 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10906 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10907 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10909 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10910 | |
| 10911 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10912 | ASSERT_TRUE(response); |
| 10913 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10914 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10915 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10916 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10917 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10918 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10919 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10920 | } |
| 10921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10922 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10923 | HttpRequestInfo request; |
| 10924 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10925 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10926 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10927 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10928 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10929 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10930 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10931 | MockRead("\r\n"), |
| 10932 | MockRead("hello world"), |
| 10933 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10934 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10935 | }; |
| 10936 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10937 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10938 | 0); |
| 10939 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10940 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10941 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10943 | |
| 10944 | // Second transaction starts an alternative and a non-alternative Job. |
| 10945 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10946 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10947 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10948 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10949 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10950 | |
| 10951 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10952 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10953 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10954 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10955 | // Third transaction starts an alternative and a non-alternative job. |
| 10956 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10957 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10958 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10959 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10960 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10961 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10962 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10963 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10964 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10965 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10966 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10967 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10968 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10969 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10970 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10971 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10972 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10973 | }; |
| 10974 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10975 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10976 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10977 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10978 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10979 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10980 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10981 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10982 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10983 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10984 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10986 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10987 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10989 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10991 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10992 | |
| 10993 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10994 | ASSERT_TRUE(response); |
| 10995 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10996 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10997 | |
| 10998 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10999 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11000 | EXPECT_EQ("hello world", response_data); |
| 11001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11002 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11003 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11004 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11007 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11008 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11009 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11011 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11012 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11013 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11014 | |
| 11015 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11016 | ASSERT_TRUE(response); |
| 11017 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11018 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11019 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11020 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11021 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11022 | EXPECT_EQ("hello!", response_data); |
| 11023 | |
| 11024 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11025 | ASSERT_TRUE(response); |
| 11026 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11027 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11028 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11029 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11030 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11031 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11032 | } |
| 11033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11034 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11035 | HttpRequestInfo request; |
| 11036 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11037 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11038 | |
| 11039 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11040 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11041 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11042 | MockRead("\r\n"), |
| 11043 | MockRead("hello world"), |
| 11044 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11045 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11046 | }; |
| 11047 | |
| 11048 | StaticSocketDataProvider first_transaction( |
| 11049 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11050 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11051 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11052 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11054 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11055 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11056 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11057 | NULL, 0, NULL, 0); |
| 11058 | hanging_alternate_protocol_socket.set_connect_data( |
| 11059 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11060 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11061 | &hanging_alternate_protocol_socket); |
| 11062 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11063 | // 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] | 11064 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11065 | NULL, 0); |
| 11066 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11069 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11072 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11073 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11075 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11077 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11078 | |
| 11079 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11080 | ASSERT_TRUE(response); |
| 11081 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11083 | |
| 11084 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11085 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11086 | EXPECT_EQ("hello world", response_data); |
| 11087 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11088 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11089 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11090 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11092 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11093 | |
| 11094 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11095 | ASSERT_TRUE(response); |
| 11096 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11097 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11098 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11099 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11100 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11101 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11102 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11103 | } |
| 11104 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11105 | class CapturingProxyResolver : public ProxyResolver { |
| 11106 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11107 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11108 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11109 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11110 | int GetProxyForURL(const GURL& url, |
| 11111 | ProxyInfo* results, |
| 11112 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11113 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11114 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11115 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11116 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11117 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11118 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11119 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11120 | } |
| 11121 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11122 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11123 | |
| 11124 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11125 | std::vector<GURL> resolved_; |
| 11126 | |
| 11127 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11128 | }; |
| 11129 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11130 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11131 | public: |
| 11132 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11133 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11134 | |
| 11135 | int CreateProxyResolver( |
| 11136 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11137 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11138 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11139 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11140 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11141 | return OK; |
| 11142 | } |
| 11143 | |
| 11144 | private: |
| 11145 | ProxyResolver* resolver_; |
| 11146 | }; |
| 11147 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11148 | // Test that proxy is resolved using the origin url, |
| 11149 | // regardless of the alternative server. |
| 11150 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11151 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11152 | ProxyConfig proxy_config; |
| 11153 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11154 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11155 | auto proxy_config_service = |
| 11156 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11157 | |
| 11158 | CapturingProxyResolver capturing_proxy_resolver; |
| 11159 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11160 | &capturing_proxy_resolver); |
| 11161 | |
| 11162 | TestNetLog net_log; |
| 11163 | |
| 11164 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11165 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11166 | &net_log); |
| 11167 | |
| 11168 | session_deps_.net_log = &net_log; |
| 11169 | |
| 11170 | // Configure alternative service with a hostname that is not bypassed by the |
| 11171 | // proxy. |
| 11172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11173 | HttpServerProperties* http_server_properties = |
| 11174 | session->http_server_properties(); |
| 11175 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11176 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11177 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11178 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11179 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11180 | expiration); |
| 11181 | |
| 11182 | // Non-alternative job should hang. |
| 11183 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11184 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11185 | nullptr, 0); |
| 11186 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11187 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11188 | &hanging_alternate_protocol_socket); |
| 11189 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11190 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11191 | |
| 11192 | HttpRequestInfo request; |
| 11193 | request.method = "GET"; |
| 11194 | request.url = GURL("https://www.example.org/"); |
| 11195 | request.load_flags = 0; |
| 11196 | |
| 11197 | SpdySerializedFrame req( |
| 11198 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11199 | |
| 11200 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11201 | |
| 11202 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11203 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11204 | MockRead spdy_reads[] = { |
| 11205 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11206 | }; |
| 11207 | |
| 11208 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11209 | arraysize(spdy_writes)); |
| 11210 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11211 | |
| 11212 | TestCompletionCallback callback; |
| 11213 | |
| 11214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11215 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11216 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11217 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11218 | |
| 11219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11220 | ASSERT_TRUE(response); |
| 11221 | ASSERT_TRUE(response->headers); |
| 11222 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11223 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11224 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11225 | |
| 11226 | std::string response_data; |
| 11227 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11228 | EXPECT_EQ("hello!", response_data); |
| 11229 | |
| 11230 | // Origin host bypasses proxy, no resolution should have happened. |
| 11231 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11232 | } |
| 11233 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11234 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11235 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11236 | proxy_config.set_auto_detect(true); |
| 11237 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11238 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11239 | CapturingProxyResolver capturing_proxy_resolver; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11240 | session_deps_.proxy_service.reset( |
| 11241 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11242 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11243 | &capturing_proxy_resolver), |
| 11244 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11245 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11246 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11247 | |
| 11248 | HttpRequestInfo request; |
| 11249 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11250 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11251 | |
| 11252 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11253 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11254 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11255 | MockRead("\r\n"), |
| 11256 | MockRead("hello world"), |
| 11257 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11258 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11259 | }; |
| 11260 | |
| 11261 | StaticSocketDataProvider first_transaction( |
| 11262 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11263 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11264 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11265 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11267 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11268 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11269 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11270 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11272 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11273 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11274 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11275 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11276 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11277 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11278 | }; |
| 11279 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11280 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11281 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11282 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11283 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11284 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11285 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11286 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11287 | }; |
| 11288 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11289 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11290 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11291 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11292 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11293 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11294 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11295 | NULL, 0, NULL, 0); |
| 11296 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11297 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11298 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11299 | &hanging_non_alternate_protocol_socket); |
| 11300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11301 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11304 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11306 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11307 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11309 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11310 | |
| 11311 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11312 | ASSERT_TRUE(response); |
| 11313 | ASSERT_TRUE(response->headers); |
| 11314 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11315 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11316 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11317 | |
| 11318 | std::string response_data; |
| 11319 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11320 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11321 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11322 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11324 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11326 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11327 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11328 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11329 | ASSERT_TRUE(response); |
| 11330 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11331 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11332 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11333 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11334 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11335 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11336 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11337 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11338 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11339 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11340 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11341 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11342 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11343 | LoadTimingInfo load_timing_info; |
| 11344 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11345 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11346 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11347 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11348 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11349 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11350 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11351 | HttpRequestInfo request; |
| 11352 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11353 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11354 | |
| 11355 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11356 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11357 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11358 | MockRead("\r\n"), |
| 11359 | MockRead("hello world"), |
| 11360 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11361 | }; |
| 11362 | |
| 11363 | StaticSocketDataProvider first_transaction( |
| 11364 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11365 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11366 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11367 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11369 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11370 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11371 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11372 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11373 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11374 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11375 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11376 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11377 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11378 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11379 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11380 | }; |
| 11381 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11382 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11383 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11384 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11385 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11386 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11390 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11391 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11393 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11395 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11396 | |
| 11397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11398 | ASSERT_TRUE(response); |
| 11399 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11400 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11401 | |
| 11402 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11403 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11404 | EXPECT_EQ("hello world", response_data); |
| 11405 | |
| 11406 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11407 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11408 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11409 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11410 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11411 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11412 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11413 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11414 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11415 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11416 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11417 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11418 | |
| 11419 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11420 | ASSERT_TRUE(response); |
| 11421 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11422 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11423 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11424 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11425 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11426 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11427 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11428 | } |
| 11429 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11430 | // GenerateAuthToken is a mighty big test. |
| 11431 | // It tests all permutation of GenerateAuthToken behavior: |
| 11432 | // - Synchronous and Asynchronous completion. |
| 11433 | // - OK or error on completion. |
| 11434 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11435 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11436 | // - Non-authenticating and authenticating backend. |
| 11437 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11438 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11439 | // problems generating an auth token for an authenticating proxy, we don't |
| 11440 | // need to test all permutations of the backend server). |
| 11441 | // |
| 11442 | // The test proceeds by going over each of the configuration cases, and |
| 11443 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11444 | // specifies both the configuration for the test as well as the expectations |
| 11445 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11446 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11447 | static const char kServer[] = "http://www.example.com"; |
| 11448 | static const char kSecureServer[] = "https://www.example.com"; |
| 11449 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11450 | |
| 11451 | enum AuthTiming { |
| 11452 | AUTH_NONE, |
| 11453 | AUTH_SYNC, |
| 11454 | AUTH_ASYNC, |
| 11455 | }; |
| 11456 | |
| 11457 | const MockWrite kGet( |
| 11458 | "GET / HTTP/1.1\r\n" |
| 11459 | "Host: www.example.com\r\n" |
| 11460 | "Connection: keep-alive\r\n\r\n"); |
| 11461 | const MockWrite kGetProxy( |
| 11462 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11463 | "Host: www.example.com\r\n" |
| 11464 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11465 | const MockWrite kGetAuth( |
| 11466 | "GET / HTTP/1.1\r\n" |
| 11467 | "Host: www.example.com\r\n" |
| 11468 | "Connection: keep-alive\r\n" |
| 11469 | "Authorization: auth_token\r\n\r\n"); |
| 11470 | const MockWrite kGetProxyAuth( |
| 11471 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11472 | "Host: www.example.com\r\n" |
| 11473 | "Proxy-Connection: keep-alive\r\n" |
| 11474 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11475 | const MockWrite kGetAuthThroughProxy( |
| 11476 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11477 | "Host: www.example.com\r\n" |
| 11478 | "Proxy-Connection: keep-alive\r\n" |
| 11479 | "Authorization: auth_token\r\n\r\n"); |
| 11480 | const MockWrite kGetAuthWithProxyAuth( |
| 11481 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11482 | "Host: www.example.com\r\n" |
| 11483 | "Proxy-Connection: keep-alive\r\n" |
| 11484 | "Proxy-Authorization: auth_token\r\n" |
| 11485 | "Authorization: auth_token\r\n\r\n"); |
| 11486 | const MockWrite kConnect( |
| 11487 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11488 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11489 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11490 | const MockWrite kConnectProxyAuth( |
| 11491 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11492 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11493 | "Proxy-Connection: keep-alive\r\n" |
| 11494 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11495 | |
| 11496 | const MockRead kSuccess( |
| 11497 | "HTTP/1.1 200 OK\r\n" |
| 11498 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11499 | "Content-Length: 3\r\n\r\n" |
| 11500 | "Yes"); |
| 11501 | const MockRead kFailure( |
| 11502 | "Should not be called."); |
| 11503 | const MockRead kServerChallenge( |
| 11504 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11505 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11506 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11507 | "Content-Length: 14\r\n\r\n" |
| 11508 | "Unauthorized\r\n"); |
| 11509 | const MockRead kProxyChallenge( |
| 11510 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11511 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11512 | "Proxy-Connection: close\r\n" |
| 11513 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11514 | "Content-Length: 14\r\n\r\n" |
| 11515 | "Unauthorized\r\n"); |
| 11516 | const MockRead kProxyConnected( |
| 11517 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11518 | |
| 11519 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11520 | // no constructors, but the C++ compiler on Windows warns about |
| 11521 | // unspecified data in compound literals. So, moved to using constructors, |
| 11522 | // and TestRound's created with the default constructor should not be used. |
| 11523 | struct TestRound { |
| 11524 | TestRound() |
| 11525 | : expected_rv(ERR_UNEXPECTED), |
| 11526 | extra_write(NULL), |
| 11527 | extra_read(NULL) { |
| 11528 | } |
| 11529 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11530 | int expected_rv_arg) |
| 11531 | : write(write_arg), |
| 11532 | read(read_arg), |
| 11533 | expected_rv(expected_rv_arg), |
| 11534 | extra_write(NULL), |
| 11535 | extra_read(NULL) { |
| 11536 | } |
| 11537 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11538 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11539 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11540 | : write(write_arg), |
| 11541 | read(read_arg), |
| 11542 | expected_rv(expected_rv_arg), |
| 11543 | extra_write(extra_write_arg), |
| 11544 | extra_read(extra_read_arg) { |
| 11545 | } |
| 11546 | MockWrite write; |
| 11547 | MockRead read; |
| 11548 | int expected_rv; |
| 11549 | const MockWrite* extra_write; |
| 11550 | const MockRead* extra_read; |
| 11551 | }; |
| 11552 | |
| 11553 | static const int kNoSSL = 500; |
| 11554 | |
| 11555 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11556 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11557 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11558 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11559 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11560 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11561 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11562 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11563 | int num_auth_rounds; |
| 11564 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11565 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11566 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11567 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11568 | {__LINE__, |
| 11569 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11570 | AUTH_NONE, |
| 11571 | OK, |
| 11572 | kServer, |
| 11573 | AUTH_NONE, |
| 11574 | OK, |
| 11575 | 1, |
| 11576 | kNoSSL, |
| 11577 | {TestRound(kGet, kSuccess, OK)}}, |
| 11578 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11579 | {__LINE__, |
| 11580 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11581 | AUTH_NONE, |
| 11582 | OK, |
| 11583 | kServer, |
| 11584 | AUTH_SYNC, |
| 11585 | OK, |
| 11586 | 2, |
| 11587 | kNoSSL, |
| 11588 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11589 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11590 | {__LINE__, |
| 11591 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11592 | AUTH_NONE, |
| 11593 | OK, |
| 11594 | kServer, |
| 11595 | AUTH_SYNC, |
| 11596 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11597 | 3, |
| 11598 | kNoSSL, |
| 11599 | {TestRound(kGet, kServerChallenge, OK), |
| 11600 | TestRound(kGet, kServerChallenge, OK), |
| 11601 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11602 | {__LINE__, |
| 11603 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11604 | AUTH_NONE, |
| 11605 | OK, |
| 11606 | kServer, |
| 11607 | AUTH_SYNC, |
| 11608 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11609 | 2, |
| 11610 | kNoSSL, |
| 11611 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11612 | {__LINE__, |
| 11613 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11614 | AUTH_NONE, |
| 11615 | OK, |
| 11616 | kServer, |
| 11617 | AUTH_SYNC, |
| 11618 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11619 | 2, |
| 11620 | kNoSSL, |
| 11621 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11622 | {__LINE__, |
| 11623 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11624 | AUTH_SYNC, |
| 11625 | ERR_FAILED, |
| 11626 | kServer, |
| 11627 | AUTH_NONE, |
| 11628 | OK, |
| 11629 | 2, |
| 11630 | kNoSSL, |
| 11631 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11632 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11633 | {__LINE__, |
| 11634 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11635 | AUTH_ASYNC, |
| 11636 | ERR_FAILED, |
| 11637 | kServer, |
| 11638 | AUTH_NONE, |
| 11639 | OK, |
| 11640 | 2, |
| 11641 | kNoSSL, |
| 11642 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11643 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11644 | {__LINE__, |
| 11645 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11646 | AUTH_NONE, |
| 11647 | OK, |
| 11648 | kServer, |
| 11649 | AUTH_SYNC, |
| 11650 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11651 | 2, |
| 11652 | kNoSSL, |
| 11653 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11654 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11655 | {__LINE__, |
| 11656 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11657 | AUTH_NONE, |
| 11658 | OK, |
| 11659 | kServer, |
| 11660 | AUTH_ASYNC, |
| 11661 | ERR_FAILED, |
| 11662 | 2, |
| 11663 | kNoSSL, |
| 11664 | {TestRound(kGet, kServerChallenge, OK), |
| 11665 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11666 | {__LINE__, |
| 11667 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11668 | AUTH_NONE, |
| 11669 | OK, |
| 11670 | kServer, |
| 11671 | AUTH_ASYNC, |
| 11672 | OK, |
| 11673 | 2, |
| 11674 | kNoSSL, |
| 11675 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11676 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11677 | {__LINE__, |
| 11678 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11679 | AUTH_NONE, |
| 11680 | OK, |
| 11681 | kServer, |
| 11682 | AUTH_ASYNC, |
| 11683 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11684 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11685 | kNoSSL, |
| 11686 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11687 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11688 | TestRound(kGet, kServerChallenge, OK), |
| 11689 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11690 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11691 | {__LINE__, |
| 11692 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11693 | AUTH_NONE, |
| 11694 | OK, |
| 11695 | kServer, |
| 11696 | AUTH_NONE, |
| 11697 | OK, |
| 11698 | 1, |
| 11699 | kNoSSL, |
| 11700 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11701 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11702 | {__LINE__, |
| 11703 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11704 | AUTH_NONE, |
| 11705 | OK, |
| 11706 | kServer, |
| 11707 | AUTH_SYNC, |
| 11708 | OK, |
| 11709 | 2, |
| 11710 | kNoSSL, |
| 11711 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11712 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11713 | {__LINE__, |
| 11714 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11715 | AUTH_NONE, |
| 11716 | OK, |
| 11717 | kServer, |
| 11718 | AUTH_SYNC, |
| 11719 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11720 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11721 | kNoSSL, |
| 11722 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11723 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11724 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11725 | {__LINE__, |
| 11726 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11727 | AUTH_NONE, |
| 11728 | OK, |
| 11729 | kServer, |
| 11730 | AUTH_ASYNC, |
| 11731 | OK, |
| 11732 | 2, |
| 11733 | kNoSSL, |
| 11734 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11735 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11736 | {__LINE__, |
| 11737 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11738 | AUTH_NONE, |
| 11739 | OK, |
| 11740 | kServer, |
| 11741 | AUTH_ASYNC, |
| 11742 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11743 | 2, |
| 11744 | kNoSSL, |
| 11745 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11746 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11747 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11748 | {__LINE__, |
| 11749 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11750 | AUTH_SYNC, |
| 11751 | OK, |
| 11752 | kServer, |
| 11753 | AUTH_NONE, |
| 11754 | OK, |
| 11755 | 2, |
| 11756 | kNoSSL, |
| 11757 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11758 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11759 | {__LINE__, |
| 11760 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11761 | AUTH_SYNC, |
| 11762 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11763 | kServer, |
| 11764 | AUTH_NONE, |
| 11765 | OK, |
| 11766 | 2, |
| 11767 | kNoSSL, |
| 11768 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11769 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11770 | {__LINE__, |
| 11771 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11772 | AUTH_ASYNC, |
| 11773 | OK, |
| 11774 | kServer, |
| 11775 | AUTH_NONE, |
| 11776 | OK, |
| 11777 | 2, |
| 11778 | kNoSSL, |
| 11779 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11780 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11781 | {__LINE__, |
| 11782 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11783 | AUTH_ASYNC, |
| 11784 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11785 | kServer, |
| 11786 | AUTH_NONE, |
| 11787 | OK, |
| 11788 | 2, |
| 11789 | kNoSSL, |
| 11790 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11791 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11792 | {__LINE__, |
| 11793 | kProxy, |
| 11794 | AUTH_ASYNC, |
| 11795 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11796 | kServer, |
| 11797 | AUTH_NONE, |
| 11798 | OK, |
| 11799 | 3, |
| 11800 | kNoSSL, |
| 11801 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11802 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11803 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11804 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11805 | {__LINE__, |
| 11806 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11807 | AUTH_SYNC, |
| 11808 | OK, |
| 11809 | kServer, |
| 11810 | AUTH_SYNC, |
| 11811 | OK, |
| 11812 | 3, |
| 11813 | kNoSSL, |
| 11814 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11815 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11816 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11817 | {__LINE__, |
| 11818 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11819 | AUTH_SYNC, |
| 11820 | OK, |
| 11821 | kServer, |
| 11822 | AUTH_SYNC, |
| 11823 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11824 | 3, |
| 11825 | kNoSSL, |
| 11826 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11827 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11828 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11829 | {__LINE__, |
| 11830 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11831 | AUTH_ASYNC, |
| 11832 | OK, |
| 11833 | kServer, |
| 11834 | AUTH_SYNC, |
| 11835 | OK, |
| 11836 | 3, |
| 11837 | kNoSSL, |
| 11838 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11839 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11840 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11841 | {__LINE__, |
| 11842 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11843 | AUTH_ASYNC, |
| 11844 | OK, |
| 11845 | kServer, |
| 11846 | AUTH_SYNC, |
| 11847 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11848 | 3, |
| 11849 | kNoSSL, |
| 11850 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11851 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11852 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11853 | {__LINE__, |
| 11854 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11855 | AUTH_SYNC, |
| 11856 | OK, |
| 11857 | kServer, |
| 11858 | AUTH_ASYNC, |
| 11859 | OK, |
| 11860 | 3, |
| 11861 | kNoSSL, |
| 11862 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11863 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11864 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11865 | {__LINE__, |
| 11866 | kProxy, |
| 11867 | AUTH_SYNC, |
| 11868 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11869 | kServer, |
| 11870 | AUTH_ASYNC, |
| 11871 | OK, |
| 11872 | 4, |
| 11873 | kNoSSL, |
| 11874 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11875 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11876 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11877 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11878 | {__LINE__, |
| 11879 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11880 | AUTH_SYNC, |
| 11881 | OK, |
| 11882 | kServer, |
| 11883 | AUTH_ASYNC, |
| 11884 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11885 | 3, |
| 11886 | kNoSSL, |
| 11887 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11888 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11889 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11890 | {__LINE__, |
| 11891 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11892 | AUTH_ASYNC, |
| 11893 | OK, |
| 11894 | kServer, |
| 11895 | AUTH_ASYNC, |
| 11896 | OK, |
| 11897 | 3, |
| 11898 | kNoSSL, |
| 11899 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11900 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11901 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11902 | {__LINE__, |
| 11903 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11904 | AUTH_ASYNC, |
| 11905 | OK, |
| 11906 | kServer, |
| 11907 | AUTH_ASYNC, |
| 11908 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11909 | 3, |
| 11910 | kNoSSL, |
| 11911 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11912 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11913 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11914 | {__LINE__, |
| 11915 | kProxy, |
| 11916 | AUTH_ASYNC, |
| 11917 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11918 | kServer, |
| 11919 | AUTH_ASYNC, |
| 11920 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11921 | 4, |
| 11922 | kNoSSL, |
| 11923 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11924 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11925 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11926 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11927 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11928 | {__LINE__, |
| 11929 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11930 | AUTH_NONE, |
| 11931 | OK, |
| 11932 | kSecureServer, |
| 11933 | AUTH_NONE, |
| 11934 | OK, |
| 11935 | 1, |
| 11936 | 0, |
| 11937 | {TestRound(kGet, kSuccess, OK)}}, |
| 11938 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11939 | {__LINE__, |
| 11940 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11941 | AUTH_NONE, |
| 11942 | OK, |
| 11943 | kSecureServer, |
| 11944 | AUTH_SYNC, |
| 11945 | OK, |
| 11946 | 2, |
| 11947 | 0, |
| 11948 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11949 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11950 | {__LINE__, |
| 11951 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11952 | AUTH_NONE, |
| 11953 | OK, |
| 11954 | kSecureServer, |
| 11955 | AUTH_SYNC, |
| 11956 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11957 | 2, |
| 11958 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11959 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11960 | {__LINE__, |
| 11961 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11962 | AUTH_NONE, |
| 11963 | OK, |
| 11964 | kSecureServer, |
| 11965 | AUTH_ASYNC, |
| 11966 | OK, |
| 11967 | 2, |
| 11968 | 0, |
| 11969 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11970 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11971 | {__LINE__, |
| 11972 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11973 | AUTH_NONE, |
| 11974 | OK, |
| 11975 | kSecureServer, |
| 11976 | AUTH_ASYNC, |
| 11977 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11978 | 2, |
| 11979 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11980 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11981 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11982 | {__LINE__, |
| 11983 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11984 | AUTH_NONE, |
| 11985 | OK, |
| 11986 | kSecureServer, |
| 11987 | AUTH_NONE, |
| 11988 | OK, |
| 11989 | 1, |
| 11990 | 0, |
| 11991 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11992 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11993 | {__LINE__, |
| 11994 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11995 | AUTH_NONE, |
| 11996 | OK, |
| 11997 | kSecureServer, |
| 11998 | AUTH_SYNC, |
| 11999 | OK, |
| 12000 | 2, |
| 12001 | 0, |
| 12002 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12003 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12004 | {__LINE__, |
| 12005 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12006 | AUTH_NONE, |
| 12007 | OK, |
| 12008 | kSecureServer, |
| 12009 | AUTH_SYNC, |
| 12010 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12011 | 2, |
| 12012 | 0, |
| 12013 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12014 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12015 | {__LINE__, |
| 12016 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12017 | AUTH_NONE, |
| 12018 | OK, |
| 12019 | kSecureServer, |
| 12020 | AUTH_ASYNC, |
| 12021 | OK, |
| 12022 | 2, |
| 12023 | 0, |
| 12024 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12025 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12026 | {__LINE__, |
| 12027 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12028 | AUTH_NONE, |
| 12029 | OK, |
| 12030 | kSecureServer, |
| 12031 | AUTH_ASYNC, |
| 12032 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12033 | 2, |
| 12034 | 0, |
| 12035 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12036 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12037 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12038 | {__LINE__, |
| 12039 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12040 | AUTH_SYNC, |
| 12041 | OK, |
| 12042 | kSecureServer, |
| 12043 | AUTH_NONE, |
| 12044 | OK, |
| 12045 | 2, |
| 12046 | 1, |
| 12047 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12048 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12049 | {__LINE__, |
| 12050 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12051 | AUTH_SYNC, |
| 12052 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12053 | kSecureServer, |
| 12054 | AUTH_NONE, |
| 12055 | OK, |
| 12056 | 2, |
| 12057 | kNoSSL, |
| 12058 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12059 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12060 | {__LINE__, |
| 12061 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12062 | AUTH_SYNC, |
| 12063 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12064 | kSecureServer, |
| 12065 | AUTH_NONE, |
| 12066 | OK, |
| 12067 | 2, |
| 12068 | kNoSSL, |
| 12069 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12070 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12071 | {__LINE__, |
| 12072 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12073 | AUTH_SYNC, |
| 12074 | ERR_UNEXPECTED, |
| 12075 | kSecureServer, |
| 12076 | AUTH_NONE, |
| 12077 | OK, |
| 12078 | 2, |
| 12079 | kNoSSL, |
| 12080 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12081 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12082 | {__LINE__, |
| 12083 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12084 | AUTH_ASYNC, |
| 12085 | OK, |
| 12086 | kSecureServer, |
| 12087 | AUTH_NONE, |
| 12088 | OK, |
| 12089 | 2, |
| 12090 | 1, |
| 12091 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12092 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12093 | {__LINE__, |
| 12094 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12095 | AUTH_ASYNC, |
| 12096 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12097 | kSecureServer, |
| 12098 | AUTH_NONE, |
| 12099 | OK, |
| 12100 | 2, |
| 12101 | kNoSSL, |
| 12102 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12103 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12104 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12105 | {__LINE__, |
| 12106 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12107 | AUTH_SYNC, |
| 12108 | OK, |
| 12109 | kSecureServer, |
| 12110 | AUTH_SYNC, |
| 12111 | OK, |
| 12112 | 3, |
| 12113 | 1, |
| 12114 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12115 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12116 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12117 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12118 | {__LINE__, |
| 12119 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12120 | AUTH_SYNC, |
| 12121 | OK, |
| 12122 | kSecureServer, |
| 12123 | AUTH_SYNC, |
| 12124 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12125 | 3, |
| 12126 | 1, |
| 12127 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12128 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12129 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12130 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12131 | {__LINE__, |
| 12132 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12133 | AUTH_ASYNC, |
| 12134 | OK, |
| 12135 | kSecureServer, |
| 12136 | AUTH_SYNC, |
| 12137 | OK, |
| 12138 | 3, |
| 12139 | 1, |
| 12140 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12141 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12142 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12143 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12144 | {__LINE__, |
| 12145 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12146 | AUTH_ASYNC, |
| 12147 | OK, |
| 12148 | kSecureServer, |
| 12149 | AUTH_SYNC, |
| 12150 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12151 | 3, |
| 12152 | 1, |
| 12153 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12154 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12155 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12156 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12157 | {__LINE__, |
| 12158 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12159 | AUTH_SYNC, |
| 12160 | OK, |
| 12161 | kSecureServer, |
| 12162 | AUTH_ASYNC, |
| 12163 | OK, |
| 12164 | 3, |
| 12165 | 1, |
| 12166 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12167 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12168 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12169 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12170 | {__LINE__, |
| 12171 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12172 | AUTH_SYNC, |
| 12173 | OK, |
| 12174 | kSecureServer, |
| 12175 | AUTH_ASYNC, |
| 12176 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12177 | 3, |
| 12178 | 1, |
| 12179 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12180 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12181 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12182 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12183 | {__LINE__, |
| 12184 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12185 | AUTH_ASYNC, |
| 12186 | OK, |
| 12187 | kSecureServer, |
| 12188 | AUTH_ASYNC, |
| 12189 | OK, |
| 12190 | 3, |
| 12191 | 1, |
| 12192 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12193 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12194 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12195 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12196 | {__LINE__, |
| 12197 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12198 | AUTH_ASYNC, |
| 12199 | OK, |
| 12200 | kSecureServer, |
| 12201 | AUTH_ASYNC, |
| 12202 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12203 | 3, |
| 12204 | 1, |
| 12205 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12206 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12207 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12208 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12209 | {__LINE__, |
| 12210 | kProxy, |
| 12211 | AUTH_ASYNC, |
| 12212 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12213 | kSecureServer, |
| 12214 | AUTH_ASYNC, |
| 12215 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12216 | 4, |
| 12217 | 2, |
| 12218 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12219 | TestRound(kConnect, kProxyChallenge, OK), |
| 12220 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12221 | &kServerChallenge), |
| 12222 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12223 | }; |
| 12224 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12225 | for (const auto& test_config : test_configs) { |
| 12226 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12227 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12228 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12229 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12230 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12231 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12232 | |
| 12233 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12234 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12235 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12236 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12237 | std::string auth_challenge = "Mock realm=proxy"; |
| 12238 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12239 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12240 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12241 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12242 | empty_ssl_info, origin, |
| 12243 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12244 | auth_handler->SetGenerateExpectation( |
| 12245 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12246 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12247 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12248 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12249 | } |
| 12250 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12251 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12252 | std::string auth_challenge = "Mock realm=server"; |
| 12253 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12254 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12255 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12256 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12257 | empty_ssl_info, origin, |
| 12258 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12259 | auth_handler->SetGenerateExpectation( |
| 12260 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12261 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12262 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12263 | |
| 12264 | // The second handler always succeeds. It should only be used where there |
| 12265 | // are multiple auth sessions for server auth in the same network |
| 12266 | // transaction using the same auth scheme. |
| 12267 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12268 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12269 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12270 | empty_ssl_info, origin, |
| 12271 | NetLogWithSource()); |
| 12272 | second_handler->SetGenerateExpectation(true, OK); |
| 12273 | auth_factory->AddMockHandler(second_handler.release(), |
| 12274 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12275 | } |
| 12276 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12277 | session_deps_.proxy_service = |
| 12278 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12279 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12280 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12281 | } |
| 12282 | |
| 12283 | HttpRequestInfo request; |
| 12284 | request.method = "GET"; |
| 12285 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12286 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12288 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12289 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12290 | |
| 12291 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12292 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12293 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12294 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12295 | |
| 12296 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12297 | mock_reads.back().push_back(read_write_round.read); |
| 12298 | mock_writes.back().push_back(read_write_round.write); |
| 12299 | |
| 12300 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12301 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12302 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12303 | mock_reads.push_back(std::vector<MockRead>()); |
| 12304 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12305 | } |
| 12306 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12307 | if (read_write_round.extra_read) { |
| 12308 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12309 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12310 | if (read_write_round.extra_write) { |
| 12311 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12312 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12313 | |
| 12314 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12315 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12316 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12317 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12318 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12319 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12320 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12321 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12322 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12323 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12324 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12325 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12326 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12327 | } |
| 12328 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12329 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12330 | // they are as well. |
| 12331 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12332 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12333 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 12334 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12335 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12336 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12337 | int rv; |
| 12338 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12339 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12340 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12341 | rv = trans.RestartWithAuth( |
| 12342 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12343 | } |
| 12344 | if (rv == ERR_IO_PENDING) |
| 12345 | rv = callback.WaitForResult(); |
| 12346 | |
| 12347 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12348 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12349 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12350 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12351 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12352 | continue; |
| 12353 | } |
| 12354 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12355 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12356 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12357 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12358 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12359 | } |
| 12360 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12361 | } |
| 12362 | } |
| 12363 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12364 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12365 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12366 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12367 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12368 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12369 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12370 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12371 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12372 | |
| 12373 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12374 | auth_handler->set_connection_based(true); |
| 12375 | std::string auth_challenge = "Mock realm=server"; |
| 12376 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12377 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12378 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12379 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12380 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12381 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12382 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12383 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12384 | int rv = OK; |
| 12385 | const HttpResponseInfo* response = NULL; |
| 12386 | HttpRequestInfo request; |
| 12387 | request.method = "GET"; |
| 12388 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12389 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12391 | |
| 12392 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12393 | // to validate that the TCP socket is not released to the pool between |
| 12394 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12395 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12396 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12397 | 50, // Max sockets for pool |
| 12398 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12399 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12400 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12401 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12402 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12403 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12404 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12407 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12408 | |
| 12409 | const MockWrite kGet( |
| 12410 | "GET / HTTP/1.1\r\n" |
| 12411 | "Host: www.example.com\r\n" |
| 12412 | "Connection: keep-alive\r\n\r\n"); |
| 12413 | const MockWrite kGetAuth( |
| 12414 | "GET / HTTP/1.1\r\n" |
| 12415 | "Host: www.example.com\r\n" |
| 12416 | "Connection: keep-alive\r\n" |
| 12417 | "Authorization: auth_token\r\n\r\n"); |
| 12418 | |
| 12419 | const MockRead kServerChallenge( |
| 12420 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12421 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12422 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12423 | "Content-Length: 14\r\n\r\n" |
| 12424 | "Unauthorized\r\n"); |
| 12425 | const MockRead kSuccess( |
| 12426 | "HTTP/1.1 200 OK\r\n" |
| 12427 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12428 | "Content-Length: 3\r\n\r\n" |
| 12429 | "Yes"); |
| 12430 | |
| 12431 | MockWrite writes[] = { |
| 12432 | // First round |
| 12433 | kGet, |
| 12434 | // Second round |
| 12435 | kGetAuth, |
| 12436 | // Third round |
| 12437 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12438 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12439 | kGetAuth, |
| 12440 | // Competing request |
| 12441 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12442 | }; |
| 12443 | MockRead reads[] = { |
| 12444 | // First round |
| 12445 | kServerChallenge, |
| 12446 | // Second round |
| 12447 | kServerChallenge, |
| 12448 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12449 | kServerChallenge, |
| 12450 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12451 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12452 | // Competing response |
| 12453 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12454 | }; |
| 12455 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12456 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12457 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12458 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12459 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12460 | |
| 12461 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12462 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12463 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12464 | if (rv == ERR_IO_PENDING) |
| 12465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12466 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12467 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12468 | ASSERT_TRUE(response); |
| 12469 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12470 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12471 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12472 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12473 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12474 | // In between rounds, another request comes in for the same domain. |
| 12475 | // It should not be able to grab the TCP socket that trans has already |
| 12476 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12477 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12478 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12479 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12480 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12482 | // callback_compete.WaitForResult at this point would stall forever, |
| 12483 | // since the HttpNetworkTransaction does not release the request back to |
| 12484 | // the pool until after authentication completes. |
| 12485 | |
| 12486 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12487 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12488 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12489 | if (rv == ERR_IO_PENDING) |
| 12490 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12491 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12492 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12493 | ASSERT_TRUE(response); |
| 12494 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12495 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12496 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12497 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12498 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12499 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12500 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12501 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12502 | if (rv == ERR_IO_PENDING) |
| 12503 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12504 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12505 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12506 | ASSERT_TRUE(response); |
| 12507 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12508 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12509 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12510 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12511 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12512 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12513 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12514 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12515 | if (rv == ERR_IO_PENDING) |
| 12516 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12517 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12518 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12519 | ASSERT_TRUE(response); |
| 12520 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12521 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12522 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12523 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12524 | // auth handler should transition to a DONE state in concert with the remote |
| 12525 | // server. But that's not something we can test here with a mock handler. |
| 12526 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12527 | auth_handler->state()); |
| 12528 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12529 | // Read the body since the fourth round was successful. This will also |
| 12530 | // release the socket back to the pool. |
| 12531 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12532 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12533 | if (rv == ERR_IO_PENDING) |
| 12534 | rv = callback.WaitForResult(); |
| 12535 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12536 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12537 | EXPECT_EQ(0, rv); |
| 12538 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12539 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12540 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12541 | |
| 12542 | // The competing request can now finish. Wait for the headers and then |
| 12543 | // read the body. |
| 12544 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12545 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12546 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12547 | if (rv == ERR_IO_PENDING) |
| 12548 | rv = callback.WaitForResult(); |
| 12549 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12550 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12551 | EXPECT_EQ(0, rv); |
| 12552 | |
| 12553 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12554 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12555 | } |
| 12556 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12557 | // This tests the case that a request is issued via http instead of spdy after |
| 12558 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12559 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12560 | HttpRequestInfo request; |
| 12561 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12562 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12563 | |
| 12564 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12565 | MockWrite( |
| 12566 | "GET / HTTP/1.1\r\n" |
| 12567 | "Host: www.example.org\r\n" |
| 12568 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12569 | }; |
| 12570 | |
| 12571 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12572 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12573 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12574 | MockRead("\r\n"), |
| 12575 | MockRead("hello world"), |
| 12576 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12577 | }; |
| 12578 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12579 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12580 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12581 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12583 | |
| 12584 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12585 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12588 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12593 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12594 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12595 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12596 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12598 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12599 | ASSERT_TRUE(response); |
| 12600 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12601 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12602 | |
| 12603 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12604 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12605 | EXPECT_EQ("hello world", response_data); |
| 12606 | |
| 12607 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12608 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12609 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12610 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12611 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12612 | // immediate server closing of the socket. |
| 12613 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12614 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12615 | HttpRequestInfo request; |
| 12616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12617 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12618 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12619 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12620 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12621 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12622 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12623 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12624 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12625 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12626 | |
| 12627 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12628 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12629 | }; |
| 12630 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12631 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12632 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12633 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12635 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12642 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12643 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12644 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12645 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12646 | // it gets it. This is needed since the auth handler may get destroyed |
| 12647 | // before we get a chance to query it. |
| 12648 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12649 | public: |
| 12650 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12651 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12652 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12653 | |
| 12654 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12655 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12656 | const HttpRequestInfo* request, |
| 12657 | const CompletionCallback& callback, |
| 12658 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12659 | *url_ = request->url; |
| 12660 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12661 | credentials, request, callback, auth_token); |
| 12662 | } |
| 12663 | |
| 12664 | private: |
| 12665 | GURL* url_; |
| 12666 | }; |
| 12667 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12668 | // Test that if we cancel the transaction as the connection is completing, that |
| 12669 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12670 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12671 | // Setup everything about the connection to complete synchronously, so that |
| 12672 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12673 | // for is the callback from the HttpStreamRequest. |
| 12674 | // Then cancel the transaction. |
| 12675 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12676 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12677 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12678 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12679 | MockRead(SYNCHRONOUS, "hello world"), |
| 12680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12681 | }; |
| 12682 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12683 | HttpRequestInfo request; |
| 12684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12685 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12686 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12689 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12690 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12691 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12692 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12693 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12696 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12697 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12698 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12699 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12701 | trans.reset(); // Cancel the transaction here. |
| 12702 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12703 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12704 | } |
| 12705 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12706 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12707 | // stream is drained properly and added back to the socket pool. The main |
| 12708 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12709 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12710 | // deleted. |
| 12711 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12712 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12713 | MockRead data_reads[] = { |
| 12714 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12715 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12716 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12717 | MockRead(ASYNC, "1"), |
| 12718 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12719 | // HttpNetworkTransaction has been deleted. |
| 12720 | MockRead(ASYNC, "2"), |
| 12721 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12722 | }; |
| 12723 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12727 | |
| 12728 | { |
| 12729 | HttpRequestInfo request; |
| 12730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12731 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12732 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12734 | TestCompletionCallback callback; |
| 12735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12736 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12738 | callback.WaitForResult(); |
| 12739 | |
| 12740 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12741 | ASSERT_TRUE(response); |
| 12742 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12743 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12744 | |
| 12745 | // The transaction and HttpRequestInfo are deleted. |
| 12746 | } |
| 12747 | |
| 12748 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12749 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12750 | |
| 12751 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12752 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12753 | } |
| 12754 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12755 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12756 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12757 | session_deps_.proxy_service = |
| 12758 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12759 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12760 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12762 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12763 | HttpRequestInfo request; |
| 12764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12766 | |
| 12767 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12768 | MockWrite( |
| 12769 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12770 | "Host: www.example.org\r\n" |
| 12771 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12772 | }; |
| 12773 | |
| 12774 | MockRead data_reads1[] = { |
| 12775 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12776 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12777 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12778 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12779 | }; |
| 12780 | |
| 12781 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12782 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12783 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12785 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12788 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12789 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12790 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12791 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12793 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12795 | |
| 12796 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12797 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12799 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12800 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12801 | |
| 12802 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12803 | EXPECT_EQ(200, response->headers->response_code()); |
| 12804 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12805 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12806 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12807 | HostPortPair::FromString("myproxy:70")), |
| 12808 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12809 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12810 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12811 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12812 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12813 | |
| 12814 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12815 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12816 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12817 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12818 | } |
| 12819 | |
| 12820 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12821 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12822 | session_deps_.proxy_service = |
| 12823 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12824 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12825 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12827 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12828 | HttpRequestInfo request; |
| 12829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12830 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12831 | |
| 12832 | // Since we have proxy, should try to establish tunnel. |
| 12833 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12834 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12835 | "Host: www.example.org:443\r\n" |
| 12836 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12837 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12838 | MockWrite("GET / HTTP/1.1\r\n" |
| 12839 | "Host: www.example.org\r\n" |
| 12840 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12841 | }; |
| 12842 | |
| 12843 | MockRead data_reads1[] = { |
| 12844 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12845 | |
| 12846 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12848 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12849 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12850 | }; |
| 12851 | |
| 12852 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12853 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12855 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12858 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12860 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12861 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12862 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12863 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12864 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12866 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12868 | |
| 12869 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12870 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12871 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12872 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12873 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12874 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12875 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12876 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12877 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12878 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12879 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12881 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12882 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12883 | |
| 12884 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12885 | EXPECT_EQ(200, response->headers->response_code()); |
| 12886 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12887 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12888 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12889 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12890 | HostPortPair::FromString("myproxy:70")), |
| 12891 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12892 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12893 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12894 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12895 | |
| 12896 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12897 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12898 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12899 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12900 | } |
| 12901 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12902 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12903 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12904 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12905 | session_deps_.proxy_service = |
| 12906 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12907 | BoundTestNetLog log; |
| 12908 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12910 | |
| 12911 | HttpRequestInfo request; |
| 12912 | request.method = "GET"; |
| 12913 | request.url = GURL("https://[::1]:443/"); |
| 12914 | |
| 12915 | // Since we have proxy, should try to establish tunnel. |
| 12916 | MockWrite data_writes1[] = { |
| 12917 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12918 | "Host: [::1]:443\r\n" |
| 12919 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12920 | |
| 12921 | MockWrite("GET / HTTP/1.1\r\n" |
| 12922 | "Host: [::1]\r\n" |
| 12923 | "Connection: keep-alive\r\n\r\n"), |
| 12924 | }; |
| 12925 | |
| 12926 | MockRead data_reads1[] = { |
| 12927 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12928 | |
| 12929 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12930 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12931 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12932 | MockRead(SYNCHRONOUS, OK), |
| 12933 | }; |
| 12934 | |
| 12935 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12936 | data_writes1, arraysize(data_writes1)); |
| 12937 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12938 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12940 | |
| 12941 | TestCompletionCallback callback1; |
| 12942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12945 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12947 | |
| 12948 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12949 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12950 | TestNetLogEntry::List entries; |
| 12951 | log.GetEntries(&entries); |
| 12952 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12953 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12954 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12955 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12956 | entries, pos, |
| 12957 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12958 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12960 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12961 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12962 | |
| 12963 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12964 | EXPECT_EQ(200, response->headers->response_code()); |
| 12965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12966 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12967 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12968 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12969 | HostPortPair::FromString("myproxy:70")), |
| 12970 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12971 | |
| 12972 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12973 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12974 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12975 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12976 | } |
| 12977 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12978 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12979 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12980 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12981 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12982 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12983 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12985 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12986 | HttpRequestInfo request; |
| 12987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12988 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12989 | |
| 12990 | // Since we have proxy, should try to establish tunnel. |
| 12991 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12992 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12993 | "Host: www.example.org:443\r\n" |
| 12994 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12995 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12996 | MockWrite("GET / HTTP/1.1\r\n" |
| 12997 | "Host: www.example.org\r\n" |
| 12998 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12999 | }; |
| 13000 | |
| 13001 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13002 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13003 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13004 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13005 | }; |
| 13006 | |
| 13007 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13008 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13009 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13010 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13011 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13013 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13017 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13019 | |
| 13020 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13021 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13022 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13023 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13024 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13025 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13026 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13027 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13028 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13029 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13030 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13031 | } |
| 13032 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13033 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13034 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13035 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13036 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13037 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13038 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13039 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13040 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13041 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13042 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13043 | }; |
| 13044 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13045 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13046 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13047 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13048 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13049 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13050 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13052 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13054 | |
| 13055 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13056 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13057 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13058 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13059 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13060 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13061 | |
| 13062 | HttpRequestInfo request; |
| 13063 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13064 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13065 | |
| 13066 | // This is the important line that marks this as a preconnect. |
| 13067 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13070 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13071 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13074 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13075 | } |
| 13076 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13077 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13078 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13079 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13080 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13081 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13082 | request_info.url = GURL("https://www.example.com/"); |
| 13083 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13084 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13085 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13086 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13087 | MockWrite data_writes[] = { |
| 13088 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13089 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13090 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13092 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13093 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13097 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13098 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13099 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13100 | rv = callback.WaitForResult(); |
| 13101 | ASSERT_EQ(error, rv); |
| 13102 | } |
| 13103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13104 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13105 | // Just check a grab bag of cert errors. |
| 13106 | static const int kErrors[] = { |
| 13107 | ERR_CERT_COMMON_NAME_INVALID, |
| 13108 | ERR_CERT_AUTHORITY_INVALID, |
| 13109 | ERR_CERT_DATE_INVALID, |
| 13110 | }; |
| 13111 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13112 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13113 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13114 | } |
| 13115 | } |
| 13116 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13117 | // Ensure that a client certificate is removed from the SSL client auth |
| 13118 | // cache when: |
| 13119 | // 1) No proxy is involved. |
| 13120 | // 2) TLS False Start is disabled. |
| 13121 | // 3) The initial TLS handshake requests a client certificate. |
| 13122 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13123 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13124 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13125 | request_info.url = GURL("https://www.example.com/"); |
| 13126 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13127 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13128 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13129 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13130 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13131 | |
| 13132 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13133 | // CertificateRequest is received for the first time, the handshake will |
| 13134 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13135 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13136 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13138 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13139 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13140 | |
| 13141 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13142 | // False Start is not being used, the result of the SSL handshake will be |
| 13143 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13144 | // matches the result of a server sending a handshake_failure alert, |
| 13145 | // rather than a Finished message, because it requires a client |
| 13146 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13147 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13148 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13150 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13151 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13152 | |
| 13153 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13154 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13155 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13156 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13157 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13158 | // requiring a client certificate, this fallback handshake should also |
| 13159 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13160 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13161 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13163 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13164 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13165 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13166 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13167 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13168 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13169 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13170 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13171 | // requiring a client certificate, this fallback handshake should also |
| 13172 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13173 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13174 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13176 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13177 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13178 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13180 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13181 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13182 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13183 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13184 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13185 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13186 | |
| 13187 | // Complete the SSL handshake, which should abort due to requiring a |
| 13188 | // client certificate. |
| 13189 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13190 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13191 | |
| 13192 | // Indicate that no certificate should be supplied. From the perspective |
| 13193 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13194 | // certificate, so this is the same as supply a |
| 13195 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13196 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13197 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13198 | |
| 13199 | // Ensure the certificate was added to the client auth cache before |
| 13200 | // allowing the connection to continue restarting. |
| 13201 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13202 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13203 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13204 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13205 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13206 | |
| 13207 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13208 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13209 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13210 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13211 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13212 | |
| 13213 | // Ensure that the client certificate is removed from the cache on a |
| 13214 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13215 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13216 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13217 | } |
| 13218 | |
| 13219 | // Ensure that a client certificate is removed from the SSL client auth |
| 13220 | // cache when: |
| 13221 | // 1) No proxy is involved. |
| 13222 | // 2) TLS False Start is enabled. |
| 13223 | // 3) The initial TLS handshake requests a client certificate. |
| 13224 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13225 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13226 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13227 | request_info.url = GURL("https://www.example.com/"); |
| 13228 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13229 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13230 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13231 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13232 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13233 | |
| 13234 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13235 | // return successfully after reading up to the peer's Certificate message. |
| 13236 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13237 | // enqueue application data to be sent in the same packet as the |
| 13238 | // ChangeCipherSpec and Finished messages. |
| 13239 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13240 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13241 | // Finished messages. If there was an error negotiating with the peer, |
| 13242 | // such as due to the peer requiring a client certificate when none was |
| 13243 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13244 | // called. |
| 13245 | |
| 13246 | // Like the non-False Start case, when a client certificate is requested by |
| 13247 | // the peer, the handshake is aborted during the Connect() call. |
| 13248 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13249 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13250 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13252 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13253 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13254 | |
| 13255 | // When a client certificate is supplied, Connect() will not be aborted |
| 13256 | // when the peer requests the certificate. Instead, the handshake will |
| 13257 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13258 | // the socket. The handshake messages are not processed until Read() is |
| 13259 | // called, which then detects that the handshake was aborted, due to the |
| 13260 | // peer sending a handshake_failure because it requires a client |
| 13261 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13262 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13263 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13265 | MockRead data2_reads[] = { |
| 13266 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13267 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13268 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13269 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13270 | |
| 13271 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13272 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13273 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13274 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13275 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13277 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13279 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13280 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13281 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13282 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13283 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13285 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13286 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13287 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13288 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13289 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13290 | ssl_data5.cert_request_info = cert_request.get(); |
| 13291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13292 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13293 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13297 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13298 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13299 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13300 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13301 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13302 | |
| 13303 | // Complete the SSL handshake, which should abort due to requiring a |
| 13304 | // client certificate. |
| 13305 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13306 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13307 | |
| 13308 | // Indicate that no certificate should be supplied. From the perspective |
| 13309 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13310 | // certificate, so this is the same as supply a |
| 13311 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13312 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13313 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13314 | |
| 13315 | // Ensure the certificate was added to the client auth cache before |
| 13316 | // allowing the connection to continue restarting. |
| 13317 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13318 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13319 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13320 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13321 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13322 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13323 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13324 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13325 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13326 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13327 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13328 | |
| 13329 | // Ensure that the client certificate is removed from the cache on a |
| 13330 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13331 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13332 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13333 | } |
| 13334 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13335 | // Ensure that a client certificate is removed from the SSL client auth |
| 13336 | // cache when: |
| 13337 | // 1) An HTTPS proxy is involved. |
| 13338 | // 3) The HTTPS proxy requests a client certificate. |
| 13339 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13340 | // proxy. |
| 13341 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13342 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13343 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13344 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13345 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13346 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13347 | |
| 13348 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13349 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13350 | |
| 13351 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13352 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13353 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13354 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13355 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13356 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13358 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13360 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13361 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13362 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13364 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13365 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13366 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13367 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13368 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13369 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13370 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13372 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13373 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13374 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13375 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13376 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13377 | requests[0].url = GURL("https://www.example.com/"); |
| 13378 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13379 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13380 | |
| 13381 | requests[1].url = GURL("http://www.example.com/"); |
| 13382 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13383 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13384 | |
| 13385 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13386 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13389 | |
| 13390 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13391 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13392 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13393 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13394 | |
| 13395 | // Complete the SSL handshake, which should abort due to requiring a |
| 13396 | // client certificate. |
| 13397 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13398 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13399 | |
| 13400 | // Indicate that no certificate should be supplied. From the perspective |
| 13401 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13402 | // certificate, so this is the same as supply a |
| 13403 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13404 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13405 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13406 | |
| 13407 | // Ensure the certificate was added to the client auth cache before |
| 13408 | // allowing the connection to continue restarting. |
| 13409 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13410 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13411 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13412 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13413 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13414 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13415 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13416 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13417 | HostPortPair("www.example.com", 443), &client_cert, |
| 13418 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13419 | |
| 13420 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13421 | // then consume ssl_data3, which should also fail. The result code is |
| 13422 | // checked against what ssl_data3 should return. |
| 13423 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13424 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13425 | |
| 13426 | // Now that the new handshake has failed, ensure that the client |
| 13427 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13428 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13429 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[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("www.example.com", 443), &client_cert, |
| 13432 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13433 | } |
| 13434 | } |
| 13435 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13436 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13437 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13438 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13440 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13441 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13442 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13443 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13444 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13445 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13446 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13447 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13448 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13449 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13450 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13451 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13452 | SpdySerializedFrame host1_resp_body( |
| 13453 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13454 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13455 | SpdySerializedFrame host2_resp_body( |
| 13456 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13457 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13458 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13459 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13460 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13461 | }; |
| 13462 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13463 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13464 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13465 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13466 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13467 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13468 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13469 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13470 | HttpRequestInfo request1; |
| 13471 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13472 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13473 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13474 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13475 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13476 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13478 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13479 | |
| 13480 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13481 | ASSERT_TRUE(response); |
| 13482 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13483 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13484 | |
| 13485 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13486 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13487 | EXPECT_EQ("hello!", response_data); |
| 13488 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13489 | // Preload mail.example.com into HostCache. |
| 13490 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13491 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13492 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13493 | std::unique_ptr<HostResolver::Request> request; |
| 13494 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13495 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13496 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13498 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13500 | |
| 13501 | HttpRequestInfo request2; |
| 13502 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13503 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13504 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13505 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13506 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13507 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13508 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13509 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13510 | |
| 13511 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13512 | ASSERT_TRUE(response); |
| 13513 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13514 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13515 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13516 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13517 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13518 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13519 | } |
| 13520 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13521 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13522 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13523 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13524 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13525 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13526 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13527 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13528 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13529 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13530 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13531 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13532 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13533 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13534 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13535 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13536 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13537 | SpdySerializedFrame host1_resp_body( |
| 13538 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13539 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13540 | SpdySerializedFrame host2_resp_body( |
| 13541 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13542 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13543 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13544 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13545 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13546 | }; |
| 13547 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13548 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13549 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13550 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13551 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13552 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13553 | |
| 13554 | TestCompletionCallback callback; |
| 13555 | HttpRequestInfo request1; |
| 13556 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13557 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13558 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13559 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13561 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13563 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13564 | |
| 13565 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13566 | ASSERT_TRUE(response); |
| 13567 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13568 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13569 | |
| 13570 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13571 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13572 | EXPECT_EQ("hello!", response_data); |
| 13573 | |
| 13574 | HttpRequestInfo request2; |
| 13575 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13576 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13577 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13578 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13579 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13580 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13582 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13583 | |
| 13584 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13585 | ASSERT_TRUE(response); |
| 13586 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13587 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13588 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13589 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13590 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13591 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13592 | } |
| 13593 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13594 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13595 | public: |
| 13596 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13597 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13598 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13599 | |
| 13600 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13601 | |
| 13602 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13603 | int Resolve(const RequestInfo& info, |
| 13604 | RequestPriority priority, |
| 13605 | AddressList* addresses, |
| 13606 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13607 | std::unique_ptr<Request>* out_req, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13608 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13609 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13610 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13611 | } |
| 13612 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13613 | int ResolveFromCache(const RequestInfo& info, |
| 13614 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13615 | const NetLogWithSource& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13616 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13617 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13618 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13619 | return rv; |
| 13620 | } |
| 13621 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13622 | MockCachingHostResolver* GetMockHostResolver() { |
| 13623 | return &host_resolver_; |
| 13624 | } |
| 13625 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13626 | private: |
| 13627 | MockCachingHostResolver host_resolver_; |
| 13628 | const HostPortPair host_port_; |
| 13629 | }; |
| 13630 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13631 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13632 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13633 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13634 | OneTimeCachingHostResolver host_resolver( |
| 13635 | HostPortPair("mail.example.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13636 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13637 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13638 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13640 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13641 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13642 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13643 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13644 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13645 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13646 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13647 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13648 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13649 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13650 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13651 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13652 | SpdySerializedFrame host1_resp_body( |
| 13653 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13654 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13655 | SpdySerializedFrame host2_resp_body( |
| 13656 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13657 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13658 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13659 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13660 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13661 | }; |
| 13662 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13663 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13664 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13665 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13666 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13667 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13668 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13669 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13670 | HttpRequestInfo request1; |
| 13671 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13672 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13673 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13674 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13676 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13678 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13679 | |
| 13680 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13681 | ASSERT_TRUE(response); |
| 13682 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13683 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13684 | |
| 13685 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13686 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13687 | EXPECT_EQ("hello!", response_data); |
| 13688 | |
| 13689 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13690 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13691 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13692 | std::unique_ptr<HostResolver::Request> request; |
| 13693 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13694 | callback.callback(), &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13696 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13697 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13698 | |
| 13699 | HttpRequestInfo request2; |
| 13700 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13701 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13702 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13703 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13704 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13705 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13707 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13708 | |
| 13709 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13710 | ASSERT_TRUE(response); |
| 13711 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13712 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13713 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13714 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13715 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13716 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13717 | } |
| 13718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13719 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13720 | const std::string https_url = "https://www.example.org:8080/"; |
| 13721 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13722 | |
| 13723 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13724 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13725 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13726 | |
| 13727 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13728 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13729 | }; |
| 13730 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13731 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13732 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13733 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13734 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13735 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13736 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13737 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13738 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13739 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13740 | |
| 13741 | // HTTP GET for the HTTP URL |
| 13742 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13743 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13744 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13745 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13746 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13747 | }; |
| 13748 | |
| 13749 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13750 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13751 | MockRead(ASYNC, 2, "hello"), |
| 13752 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13753 | }; |
| 13754 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13755 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13756 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13757 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13758 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13759 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13761 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13762 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13765 | |
| 13766 | // Start the first transaction to set up the SpdySession |
| 13767 | HttpRequestInfo request1; |
| 13768 | request1.method = "GET"; |
| 13769 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13770 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13771 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13772 | TestCompletionCallback callback1; |
| 13773 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13774 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13775 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13776 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13777 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13778 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13779 | |
| 13780 | // Now, start the HTTP request |
| 13781 | HttpRequestInfo request2; |
| 13782 | request2.method = "GET"; |
| 13783 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13784 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13785 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13786 | TestCompletionCallback callback2; |
| 13787 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13788 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13789 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13790 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13791 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13792 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13793 | } |
| 13794 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13795 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13796 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13797 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13798 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13799 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13800 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13801 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13802 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13803 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13804 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13805 | |
| 13806 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13807 | // negotiated. |
| 13808 | StaticSocketDataProvider data; |
| 13809 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13810 | |
| 13811 | // 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] | 13812 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13813 | // mocked. This way the request relies on the alternate Job. |
| 13814 | StaticSocketDataProvider data_refused; |
| 13815 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13816 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13817 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13818 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13819 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13820 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13821 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13822 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13823 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13824 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13825 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13826 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13827 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13829 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13830 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13831 | TestCompletionCallback callback; |
| 13832 | |
| 13833 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13834 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13835 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13836 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13837 | } |
| 13838 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13839 | // 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] | 13840 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13841 | // succeeds, the request should succeed, even if the latter fails because |
| 13842 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13843 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13844 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13845 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13846 | |
| 13847 | // Negotiate HTTP/1.1 with alternative. |
| 13848 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13849 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13850 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13851 | |
| 13852 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13853 | // negotiated. |
| 13854 | StaticSocketDataProvider data; |
| 13855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13856 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13857 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13858 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13859 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13861 | |
| 13862 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13863 | MockWrite("GET / HTTP/1.1\r\n" |
| 13864 | "Host: www.example.org\r\n" |
| 13865 | "Connection: keep-alive\r\n\r\n"), |
| 13866 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13867 | "Host: www.example.org\r\n" |
| 13868 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13869 | }; |
| 13870 | |
| 13871 | MockRead http_reads[] = { |
| 13872 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13873 | MockRead("Content-Type: text/html\r\n"), |
| 13874 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13875 | MockRead("foobar"), |
| 13876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13877 | MockRead("Content-Type: text/html\r\n"), |
| 13878 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13879 | MockRead("another"), |
| 13880 | }; |
| 13881 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13882 | http_writes, arraysize(http_writes)); |
| 13883 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13884 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13885 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13887 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13888 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13889 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13890 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13891 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13892 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13893 | |
| 13894 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13895 | HttpRequestInfo request1; |
| 13896 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13897 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13898 | request1.load_flags = 0; |
| 13899 | TestCompletionCallback callback1; |
| 13900 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13901 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13902 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13903 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13904 | |
| 13905 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13906 | ASSERT_TRUE(response1); |
| 13907 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13908 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13909 | |
| 13910 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13911 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13912 | EXPECT_EQ("foobar", response_data1); |
| 13913 | |
| 13914 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13915 | // for alternative service. |
| 13916 | EXPECT_TRUE( |
| 13917 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13918 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13919 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13920 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13921 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13922 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13923 | HttpRequestInfo request2; |
| 13924 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13925 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13926 | request2.load_flags = 0; |
| 13927 | TestCompletionCallback callback2; |
| 13928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13929 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13930 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13931 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13932 | |
| 13933 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13934 | ASSERT_TRUE(response2); |
| 13935 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13936 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13937 | |
| 13938 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13939 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13940 | EXPECT_EQ("another", response_data2); |
| 13941 | } |
| 13942 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13943 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13944 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13945 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13946 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13947 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13948 | HostPortPair alternative("alternative.example.org", 443); |
| 13949 | std::string origin_url = "https://origin.example.org:443"; |
| 13950 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13951 | |
| 13952 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13953 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13954 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13956 | |
| 13957 | // HTTP/1.1 data for |request1| and |request2|. |
| 13958 | MockWrite http_writes[] = { |
| 13959 | MockWrite( |
| 13960 | "GET / HTTP/1.1\r\n" |
| 13961 | "Host: alternative.example.org\r\n" |
| 13962 | "Connection: keep-alive\r\n\r\n"), |
| 13963 | MockWrite( |
| 13964 | "GET / HTTP/1.1\r\n" |
| 13965 | "Host: alternative.example.org\r\n" |
| 13966 | "Connection: keep-alive\r\n\r\n"), |
| 13967 | }; |
| 13968 | |
| 13969 | MockRead http_reads[] = { |
| 13970 | MockRead( |
| 13971 | "HTTP/1.1 200 OK\r\n" |
| 13972 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13973 | "Content-Length: 40\r\n\r\n" |
| 13974 | "first HTTP/1.1 response from alternative"), |
| 13975 | MockRead( |
| 13976 | "HTTP/1.1 200 OK\r\n" |
| 13977 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13978 | "Content-Length: 41\r\n\r\n" |
| 13979 | "second HTTP/1.1 response from alternative"), |
| 13980 | }; |
| 13981 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13982 | http_writes, arraysize(http_writes)); |
| 13983 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13984 | |
| 13985 | // This test documents that an alternate Job should not pool to an already |
| 13986 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13987 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13988 | StaticSocketDataProvider data_refused; |
| 13989 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13990 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13991 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13992 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13994 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13995 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13996 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13997 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13998 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13999 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14000 | |
| 14001 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14002 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14003 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14004 | request1.method = "GET"; |
| 14005 | request1.url = GURL(alternative_url); |
| 14006 | request1.load_flags = 0; |
| 14007 | TestCompletionCallback callback1; |
| 14008 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14009 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14010 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14011 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14012 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14013 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14014 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14015 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14016 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14017 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14018 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14019 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14020 | |
| 14021 | // Request for origin.example.org, which has an alternative service. This |
| 14022 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14023 | // 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] | 14024 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14025 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14026 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14027 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14028 | request2.method = "GET"; |
| 14029 | request2.url = GURL(origin_url); |
| 14030 | request2.load_flags = 0; |
| 14031 | TestCompletionCallback callback2; |
| 14032 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14033 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14034 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14035 | |
| 14036 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14037 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14038 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14039 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14040 | request3.method = "GET"; |
| 14041 | request3.url = GURL(alternative_url); |
| 14042 | request3.load_flags = 0; |
| 14043 | TestCompletionCallback callback3; |
| 14044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14045 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14046 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14047 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14048 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14049 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14050 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14051 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14052 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14053 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14054 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14055 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14056 | } |
| 14057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14058 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14059 | const std::string https_url = "https://www.example.org:8080/"; |
| 14060 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14061 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14062 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14063 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14064 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14065 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14066 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14067 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14068 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14069 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14070 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14071 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14072 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14073 | |
| 14074 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14075 | SpdyHeaderBlock req2_block; |
| 14076 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14077 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14078 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14079 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14080 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14081 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14082 | |
| 14083 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14084 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14085 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14086 | }; |
| 14087 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14088 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14089 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14090 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14091 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14092 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14093 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14094 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14095 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14096 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14097 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14098 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14099 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14100 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14101 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14102 | CreateMockRead(wrapped_resp1, 4), |
| 14103 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14104 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14105 | CreateMockRead(resp2, 8), |
| 14106 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14107 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14108 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14109 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14110 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14111 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14112 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14113 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14114 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14115 | session_deps_.proxy_service = |
| 14116 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14117 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14118 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14119 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14120 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14121 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14122 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14123 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14125 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14126 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14127 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14128 | |
| 14129 | // Start the first transaction to set up the SpdySession |
| 14130 | HttpRequestInfo request1; |
| 14131 | request1.method = "GET"; |
| 14132 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14133 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14134 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14135 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14136 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14137 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14138 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14139 | data1.RunUntilPaused(); |
| 14140 | base::RunLoop().RunUntilIdle(); |
| 14141 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14142 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14143 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14144 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14145 | LoadTimingInfo load_timing_info1; |
| 14146 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14147 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14148 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14149 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14150 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14151 | HttpRequestInfo request2; |
| 14152 | request2.method = "GET"; |
| 14153 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14154 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14155 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14156 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14157 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14158 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14159 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14160 | data1.RunUntilPaused(); |
| 14161 | base::RunLoop().RunUntilIdle(); |
| 14162 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14163 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14164 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14165 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14166 | |
| 14167 | LoadTimingInfo load_timing_info2; |
| 14168 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14169 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14170 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14171 | // HTTP requests over a SPDY session should have a different connection |
| 14172 | // socket_log_id than requests over a tunnel. |
| 14173 | 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] | 14174 | } |
| 14175 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14176 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14177 | // that we do not pool other origins that resolve to the same IP when |
| 14178 | // the certificate does not match the new origin. |
| 14179 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14180 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14181 | const std::string url1 = "http://www.example.org/"; |
| 14182 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14183 | const std::string ip_addr = "1.2.3.4"; |
| 14184 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14185 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14186 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14187 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14188 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14189 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14190 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14191 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14192 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14193 | |
| 14194 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14195 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14196 | }; |
| 14197 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14198 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14199 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14200 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14201 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14202 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14203 | }; |
| 14204 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14205 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14206 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14207 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14208 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14209 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14210 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14211 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14212 | |
| 14213 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14214 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14215 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14216 | |
| 14217 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14218 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14219 | }; |
| 14220 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14221 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14222 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14223 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14224 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14225 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14226 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14227 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14228 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14229 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14230 | |
| 14231 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14232 | // all others direct. |
| 14233 | ProxyConfig proxy_config; |
| 14234 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14235 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14236 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 14237 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14238 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14239 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14240 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14241 | // Load a valid cert. Note, that this does not need to |
| 14242 | // be valid for proxy because the MockSSLClientSocket does |
| 14243 | // not actually verify it. But SpdySession will use this |
| 14244 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14245 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14246 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14248 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14249 | |
| 14250 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14251 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14252 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14253 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14254 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14255 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14256 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14257 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14259 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14260 | |
| 14261 | // Start the first transaction to set up the SpdySession |
| 14262 | HttpRequestInfo request1; |
| 14263 | request1.method = "GET"; |
| 14264 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14265 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14266 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14267 | TestCompletionCallback callback1; |
| 14268 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14269 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14270 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14271 | data1.RunUntilPaused(); |
| 14272 | base::RunLoop().RunUntilIdle(); |
| 14273 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14274 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14275 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14276 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14277 | |
| 14278 | // Now, start the HTTP request |
| 14279 | HttpRequestInfo request2; |
| 14280 | request2.method = "GET"; |
| 14281 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14282 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14283 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14284 | TestCompletionCallback callback2; |
| 14285 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14286 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14287 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14288 | |
| 14289 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14290 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14291 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14292 | } |
| 14293 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14294 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14295 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14296 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14297 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14298 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14299 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14300 | |
| 14301 | MockRead reads1[] = { |
| 14302 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14303 | }; |
| 14304 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14305 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14306 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14307 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14308 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14309 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14310 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14311 | }; |
| 14312 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14313 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14314 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14315 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14316 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14317 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14318 | }; |
| 14319 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14320 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14321 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14322 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14323 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14324 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14326 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14327 | |
| 14328 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14329 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14332 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14333 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14334 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14335 | |
| 14336 | // Start the first transaction to set up the SpdySession and verify that |
| 14337 | // connection was closed. |
| 14338 | HttpRequestInfo request1; |
| 14339 | request1.method = "GET"; |
| 14340 | request1.url = GURL(https_url); |
| 14341 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14342 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14343 | TestCompletionCallback callback1; |
| 14344 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14345 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14346 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14347 | |
| 14348 | // Now, start the second request and make sure it succeeds. |
| 14349 | HttpRequestInfo request2; |
| 14350 | request2.method = "GET"; |
| 14351 | request2.url = GURL(https_url); |
| 14352 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14353 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14354 | TestCompletionCallback callback2; |
| 14355 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14356 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14357 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14358 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14359 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14360 | } |
| 14361 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14362 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14363 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14364 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14365 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14366 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14367 | |
| 14368 | // Use two different hosts with different IPs so they don't get pooled. |
| 14369 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14370 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14372 | |
| 14373 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14374 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14375 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14376 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14379 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14380 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14381 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14382 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14383 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14384 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14385 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14386 | SpdySerializedFrame host1_resp_body( |
| 14387 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14388 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14389 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14390 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14391 | }; |
| 14392 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14393 | // Use a separate test instance for the separate SpdySession that will be |
| 14394 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14395 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14396 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14397 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14398 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14399 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14400 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14401 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14402 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14403 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14404 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14405 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14406 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14407 | SpdySerializedFrame host2_resp_body( |
| 14408 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14409 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14410 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14411 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14412 | }; |
| 14413 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14414 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14415 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14416 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14417 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14418 | |
| 14419 | MockWrite http_write[] = { |
| 14420 | MockWrite("GET / HTTP/1.1\r\n" |
| 14421 | "Host: www.a.com\r\n" |
| 14422 | "Connection: keep-alive\r\n\r\n"), |
| 14423 | }; |
| 14424 | |
| 14425 | MockRead http_read[] = { |
| 14426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14427 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14428 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14429 | MockRead("hello!"), |
| 14430 | }; |
| 14431 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14432 | http_write, arraysize(http_write)); |
| 14433 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14434 | |
| 14435 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14436 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14437 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14438 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14439 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14440 | |
| 14441 | TestCompletionCallback callback; |
| 14442 | HttpRequestInfo request1; |
| 14443 | request1.method = "GET"; |
| 14444 | request1.url = GURL("https://www.a.com/"); |
| 14445 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14446 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14447 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14448 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14449 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14451 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14452 | |
| 14453 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14454 | ASSERT_TRUE(response); |
| 14455 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14456 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14457 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14458 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14459 | |
| 14460 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14461 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14462 | EXPECT_EQ("hello!", response_data); |
| 14463 | trans.reset(); |
| 14464 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14465 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14466 | |
| 14467 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14468 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14469 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14470 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14471 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14472 | HttpRequestInfo request2; |
| 14473 | request2.method = "GET"; |
| 14474 | request2.url = GURL("https://www.b.com/"); |
| 14475 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14476 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14478 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14480 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14481 | |
| 14482 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14483 | ASSERT_TRUE(response); |
| 14484 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14485 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14486 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14487 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14488 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14489 | EXPECT_EQ("hello!", response_data); |
| 14490 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14491 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14492 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14493 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14494 | |
| 14495 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14496 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14497 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14498 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14499 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14500 | HttpRequestInfo request3; |
| 14501 | request3.method = "GET"; |
| 14502 | request3.url = GURL("http://www.a.com/"); |
| 14503 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14504 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14505 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14506 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14508 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14509 | |
| 14510 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14511 | ASSERT_TRUE(response); |
| 14512 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14513 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14514 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14515 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14516 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14517 | EXPECT_EQ("hello!", response_data); |
| 14518 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14519 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14520 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14521 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14522 | } |
| 14523 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14524 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14525 | HttpRequestInfo request; |
| 14526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14527 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14528 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14531 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14532 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14533 | StaticSocketDataProvider data; |
| 14534 | data.set_connect_data(mock_connect); |
| 14535 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14536 | |
| 14537 | TestCompletionCallback callback; |
| 14538 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14539 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14541 | |
| 14542 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14543 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14544 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14545 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14546 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14547 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14548 | |
| 14549 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14550 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14551 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14552 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14553 | |
| 14554 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14555 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14556 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14557 | } |
| 14558 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14559 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14560 | HttpRequestInfo request; |
| 14561 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14562 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14565 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14566 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14567 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14568 | StaticSocketDataProvider data; |
| 14569 | data.set_connect_data(mock_connect); |
| 14570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14571 | |
| 14572 | TestCompletionCallback callback; |
| 14573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14574 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14576 | |
| 14577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14578 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14579 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14580 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14581 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14582 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14583 | |
| 14584 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14585 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14586 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14587 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14588 | |
| 14589 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14590 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14591 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14592 | } |
| 14593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14594 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14595 | HttpRequestInfo request; |
| 14596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14597 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14601 | |
| 14602 | MockWrite data_writes[] = { |
| 14603 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14604 | }; |
| 14605 | MockRead data_reads[] = { |
| 14606 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14607 | }; |
| 14608 | |
| 14609 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14610 | data_writes, arraysize(data_writes)); |
| 14611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14612 | |
| 14613 | TestCompletionCallback callback; |
| 14614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14617 | |
| 14618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14619 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14620 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14621 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14622 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14623 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14624 | } |
| 14625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14626 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14627 | HttpRequestInfo request; |
| 14628 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14629 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14633 | |
| 14634 | MockWrite data_writes[] = { |
| 14635 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14636 | }; |
| 14637 | MockRead data_reads[] = { |
| 14638 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14639 | }; |
| 14640 | |
| 14641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14642 | data_writes, arraysize(data_writes)); |
| 14643 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14644 | |
| 14645 | TestCompletionCallback callback; |
| 14646 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14647 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14649 | |
| 14650 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14651 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14652 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14653 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14654 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14655 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14656 | } |
| 14657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14658 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14659 | HttpRequestInfo request; |
| 14660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14661 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14665 | |
| 14666 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14667 | MockWrite( |
| 14668 | "GET / HTTP/1.1\r\n" |
| 14669 | "Host: www.example.org\r\n" |
| 14670 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14671 | }; |
| 14672 | MockRead data_reads[] = { |
| 14673 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14674 | }; |
| 14675 | |
| 14676 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14677 | data_writes, arraysize(data_writes)); |
| 14678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14679 | |
| 14680 | TestCompletionCallback callback; |
| 14681 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14682 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14683 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14684 | |
| 14685 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14686 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14687 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14688 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14689 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14690 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14691 | } |
| 14692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14693 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14694 | HttpRequestInfo request; |
| 14695 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14696 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14697 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14699 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14700 | |
| 14701 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14702 | MockWrite( |
| 14703 | "GET / HTTP/1.1\r\n" |
| 14704 | "Host: www.example.org\r\n" |
| 14705 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14706 | }; |
| 14707 | MockRead data_reads[] = { |
| 14708 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14709 | }; |
| 14710 | |
| 14711 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14712 | data_writes, arraysize(data_writes)); |
| 14713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14714 | |
| 14715 | TestCompletionCallback callback; |
| 14716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14719 | |
| 14720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14721 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14722 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14723 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14724 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14725 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14726 | } |
| 14727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14728 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14729 | HttpRequestInfo request; |
| 14730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14731 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14732 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14736 | |
| 14737 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14738 | MockWrite( |
| 14739 | "GET / HTTP/1.1\r\n" |
| 14740 | "Host: www.example.org\r\n" |
| 14741 | "Connection: keep-alive\r\n" |
| 14742 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14743 | }; |
| 14744 | MockRead data_reads[] = { |
| 14745 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14746 | "Content-Length: 5\r\n\r\n" |
| 14747 | "hello"), |
| 14748 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14749 | }; |
| 14750 | |
| 14751 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14752 | data_writes, arraysize(data_writes)); |
| 14753 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14754 | |
| 14755 | TestCompletionCallback callback; |
| 14756 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14757 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14759 | |
| 14760 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14762 | |
| 14763 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14764 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14765 | std::string foo; |
| 14766 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14767 | EXPECT_EQ("bar", foo); |
| 14768 | } |
| 14769 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14770 | namespace { |
| 14771 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14772 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14773 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14774 | public base::SupportsWeakPtr<FakeStream> { |
| 14775 | public: |
| 14776 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14777 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14778 | |
| 14779 | RequestPriority priority() const { return priority_; } |
| 14780 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14781 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14782 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14783 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14784 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14785 | return ERR_IO_PENDING; |
| 14786 | } |
| 14787 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14788 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14789 | HttpResponseInfo* response, |
| 14790 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14791 | ADD_FAILURE(); |
| 14792 | return ERR_UNEXPECTED; |
| 14793 | } |
| 14794 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14795 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14796 | ADD_FAILURE(); |
| 14797 | return ERR_UNEXPECTED; |
| 14798 | } |
| 14799 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14800 | int ReadResponseBody(IOBuffer* buf, |
| 14801 | int buf_len, |
| 14802 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14803 | ADD_FAILURE(); |
| 14804 | return ERR_UNEXPECTED; |
| 14805 | } |
| 14806 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14807 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14808 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14809 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14810 | ADD_FAILURE(); |
| 14811 | return false; |
| 14812 | } |
| 14813 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14814 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14815 | ADD_FAILURE(); |
| 14816 | return false; |
| 14817 | } |
| 14818 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14819 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14820 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14821 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14822 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14823 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14824 | ADD_FAILURE(); |
| 14825 | return 0; |
| 14826 | } |
| 14827 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14828 | int64_t GetTotalSentBytes() const override { |
| 14829 | ADD_FAILURE(); |
| 14830 | return 0; |
| 14831 | } |
| 14832 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14833 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14834 | ADD_FAILURE(); |
| 14835 | return false; |
| 14836 | } |
| 14837 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14838 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14839 | |
| 14840 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14841 | ADD_FAILURE(); |
| 14842 | } |
| 14843 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14844 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14845 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 14846 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 14847 | TokenBindingType tb_type, |
| 14848 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14849 | ADD_FAILURE(); |
| 14850 | return ERR_NOT_IMPLEMENTED; |
| 14851 | } |
| 14852 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14853 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14854 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14855 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14856 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14857 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14858 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14859 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14860 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14861 | private: |
| 14862 | RequestPriority priority_; |
| 14863 | |
| 14864 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14865 | }; |
| 14866 | |
| 14867 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14868 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14869 | class FakeStreamRequest : public HttpStreamRequest, |
| 14870 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14871 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14872 | FakeStreamRequest(RequestPriority priority, |
| 14873 | HttpStreamRequest::Delegate* delegate) |
| 14874 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14875 | delegate_(delegate), |
| 14876 | websocket_stream_create_helper_(NULL) {} |
| 14877 | |
| 14878 | FakeStreamRequest(RequestPriority priority, |
| 14879 | HttpStreamRequest::Delegate* delegate, |
| 14880 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14881 | : priority_(priority), |
| 14882 | delegate_(delegate), |
| 14883 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14884 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14885 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14886 | |
| 14887 | RequestPriority priority() const { return priority_; } |
| 14888 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14889 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14890 | websocket_stream_create_helper() const { |
| 14891 | return websocket_stream_create_helper_; |
| 14892 | } |
| 14893 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14894 | // Create a new FakeStream and pass it to the request's |
| 14895 | // delegate. Returns a weak pointer to the FakeStream. |
| 14896 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14897 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14898 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14899 | // immediately delete |fake_stream|. |
| 14900 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14901 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14902 | return weak_stream; |
| 14903 | } |
| 14904 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14905 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14906 | ADD_FAILURE(); |
| 14907 | return ERR_UNEXPECTED; |
| 14908 | } |
| 14909 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14910 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14911 | ADD_FAILURE(); |
| 14912 | return LoadState(); |
| 14913 | } |
| 14914 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14915 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14916 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14917 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14918 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 14919 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14920 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14921 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14922 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14923 | const ConnectionAttempts& connection_attempts() const override { |
| 14924 | static ConnectionAttempts no_attempts; |
| 14925 | return no_attempts; |
| 14926 | } |
| 14927 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14928 | private: |
| 14929 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14930 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14931 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14932 | |
| 14933 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14934 | }; |
| 14935 | |
| 14936 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14937 | class FakeStreamFactory : public HttpStreamFactory { |
| 14938 | public: |
| 14939 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14940 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14941 | |
| 14942 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14943 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14944 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14945 | return last_stream_request_; |
| 14946 | } |
| 14947 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14948 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14949 | RequestPriority priority, |
| 14950 | const SSLConfig& server_ssl_config, |
| 14951 | const SSLConfig& proxy_ssl_config, |
| 14952 | HttpStreamRequest::Delegate* delegate, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14953 | const NetLogWithSource& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14954 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14955 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14956 | return fake_request; |
| 14957 | } |
| 14958 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14959 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14960 | const HttpRequestInfo& info, |
| 14961 | RequestPriority priority, |
| 14962 | const SSLConfig& server_ssl_config, |
| 14963 | const SSLConfig& proxy_ssl_config, |
| 14964 | HttpStreamRequest::Delegate* delegate, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14965 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14966 | NOTREACHED(); |
| 14967 | return nullptr; |
| 14968 | } |
| 14969 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14970 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14971 | const HttpRequestInfo& info, |
| 14972 | RequestPriority priority, |
| 14973 | const SSLConfig& server_ssl_config, |
| 14974 | const SSLConfig& proxy_ssl_config, |
| 14975 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14976 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14977 | const NetLogWithSource& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14978 | FakeStreamRequest* fake_request = |
| 14979 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14980 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14981 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14982 | } |
| 14983 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14984 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14985 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14986 | ADD_FAILURE(); |
| 14987 | } |
| 14988 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14989 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14990 | ADD_FAILURE(); |
| 14991 | return NULL; |
| 14992 | } |
| 14993 | |
| 14994 | private: |
| 14995 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14996 | |
| 14997 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14998 | }; |
| 14999 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15000 | // TODO(ricea): Maybe unify this with the one in |
| 15001 | // url_request_http_job_unittest.cc ? |
| 15002 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15003 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15004 | FakeWebSocketBasicHandshakeStream( |
| 15005 | std::unique_ptr<ClientSocketHandle> connection, |
| 15006 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15007 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15008 | |
| 15009 | // Fake implementation of HttpStreamBase methods. |
| 15010 | // This ends up being quite "real" because this object has to really send data |
| 15011 | // on the mock socket. It might be easier to use the real implementation, but |
| 15012 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15013 | // difficult. |
| 15014 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15015 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15016 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15017 | const CompletionCallback& callback) override { |
| 15018 | state_.Initialize(request_info, priority, net_log, callback); |
| 15019 | return OK; |
| 15020 | } |
| 15021 | |
| 15022 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15023 | HttpResponseInfo* response, |
| 15024 | const CompletionCallback& callback) override { |
| 15025 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15026 | response, callback); |
| 15027 | } |
| 15028 | |
| 15029 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15030 | return parser()->ReadResponseHeaders(callback); |
| 15031 | } |
| 15032 | |
| 15033 | int ReadResponseBody(IOBuffer* buf, |
| 15034 | int buf_len, |
| 15035 | const CompletionCallback& callback) override { |
| 15036 | NOTREACHED(); |
| 15037 | return ERR_IO_PENDING; |
| 15038 | } |
| 15039 | |
| 15040 | void Close(bool not_reusable) override { |
| 15041 | if (parser()) |
| 15042 | parser()->Close(true); |
| 15043 | } |
| 15044 | |
| 15045 | bool IsResponseBodyComplete() const override { |
| 15046 | NOTREACHED(); |
| 15047 | return false; |
| 15048 | } |
| 15049 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15050 | bool IsConnectionReused() const override { |
| 15051 | NOTREACHED(); |
| 15052 | return false; |
| 15053 | } |
| 15054 | void SetConnectionReused() override { NOTREACHED(); } |
| 15055 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15056 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15057 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15058 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15059 | NOTREACHED(); |
| 15060 | return 0; |
| 15061 | } |
| 15062 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15063 | int64_t GetTotalSentBytes() const override { |
| 15064 | NOTREACHED(); |
| 15065 | return 0; |
| 15066 | } |
| 15067 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15068 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15069 | NOTREACHED(); |
| 15070 | return false; |
| 15071 | } |
| 15072 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15073 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15074 | |
| 15075 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15076 | NOTREACHED(); |
| 15077 | } |
| 15078 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15079 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15080 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15081 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15082 | TokenBindingType tb_type, |
| 15083 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15084 | ADD_FAILURE(); |
| 15085 | return ERR_NOT_IMPLEMENTED; |
| 15086 | } |
| 15087 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15088 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15089 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15090 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15091 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15092 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15093 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15094 | HttpStream* RenewStreamForAuth() override { |
| 15095 | NOTREACHED(); |
| 15096 | return nullptr; |
| 15097 | } |
| 15098 | |
| 15099 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15100 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15101 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15102 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15103 | } |
| 15104 | |
| 15105 | private: |
| 15106 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15107 | HttpBasicState state_; |
| 15108 | |
| 15109 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15110 | }; |
| 15111 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15112 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15113 | // worth doing. |
| 15114 | class FakeWebSocketStreamCreateHelper : |
| 15115 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15116 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15117 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15118 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15119 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15120 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15121 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15122 | } |
| 15123 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15124 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15125 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15126 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15127 | NOTREACHED(); |
| 15128 | return NULL; |
| 15129 | }; |
| 15130 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15131 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15132 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15133 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15134 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15135 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15136 | } |
| 15137 | }; |
| 15138 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15139 | } // namespace |
| 15140 | |
| 15141 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15142 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15143 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15145 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15146 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15147 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15148 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15149 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15150 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15151 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15152 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15153 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15154 | TestCompletionCallback callback; |
| 15155 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15156 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15157 | |
| 15158 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15159 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15160 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15161 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15162 | } |
| 15163 | |
| 15164 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15165 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15166 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15168 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15169 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15170 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15171 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15172 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15173 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15174 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15175 | TestCompletionCallback callback; |
| 15176 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15177 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15178 | |
| 15179 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15180 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15181 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15182 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15183 | |
| 15184 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15185 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15186 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15187 | } |
| 15188 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15189 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15190 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15191 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15193 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15194 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15195 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15196 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15197 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15198 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15199 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15200 | TestCompletionCallback callback; |
| 15201 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15202 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15203 | |
| 15204 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15205 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15206 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15207 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15208 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15209 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15210 | |
| 15211 | trans.SetPriority(LOWEST); |
| 15212 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15213 | } |
| 15214 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15215 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15216 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15217 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15218 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15219 | std::string test_cases[] = {"ws://www.example.org/", |
| 15220 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15221 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15223 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15224 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15225 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15226 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15227 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15228 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15229 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15230 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15231 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15232 | &websocket_stream_create_helper); |
| 15233 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15234 | TestCompletionCallback callback; |
| 15235 | request.method = "GET"; |
| 15236 | request.url = GURL(test_cases[i]); |
| 15237 | |
| 15238 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15239 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15240 | |
| 15241 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15242 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15243 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15244 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15245 | fake_request->websocket_stream_create_helper()); |
| 15246 | } |
| 15247 | } |
| 15248 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15249 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15250 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15251 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15252 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15253 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15254 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15255 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15256 | |
| 15257 | // Set up SSL request. |
| 15258 | |
| 15259 | HttpRequestInfo ssl_request; |
| 15260 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15261 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15262 | |
| 15263 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15264 | MockWrite( |
| 15265 | "GET / HTTP/1.1\r\n" |
| 15266 | "Host: www.example.org\r\n" |
| 15267 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15268 | }; |
| 15269 | MockRead ssl_reads[] = { |
| 15270 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15271 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15272 | MockRead("hello world"), |
| 15273 | MockRead(SYNCHRONOUS, OK), |
| 15274 | }; |
| 15275 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15276 | ssl_writes, arraysize(ssl_writes)); |
| 15277 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15278 | |
| 15279 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15280 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15281 | |
| 15282 | // Set up HTTP request. |
| 15283 | |
| 15284 | HttpRequestInfo http_request; |
| 15285 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15286 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15287 | |
| 15288 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15289 | MockWrite( |
| 15290 | "GET / HTTP/1.1\r\n" |
| 15291 | "Host: www.example.org\r\n" |
| 15292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15293 | }; |
| 15294 | MockRead http_reads[] = { |
| 15295 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15296 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15297 | MockRead("falafel"), |
| 15298 | MockRead(SYNCHRONOUS, OK), |
| 15299 | }; |
| 15300 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15301 | http_writes, arraysize(http_writes)); |
| 15302 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15303 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15305 | |
| 15306 | // Start the SSL request. |
| 15307 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15308 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15309 | ASSERT_EQ(ERR_IO_PENDING, |
| 15310 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15311 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15312 | |
| 15313 | // Start the HTTP request. Pool should stall. |
| 15314 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15315 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15316 | ASSERT_EQ(ERR_IO_PENDING, |
| 15317 | http_trans.Start(&http_request, http_callback.callback(), |
| 15318 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15319 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15320 | |
| 15321 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15322 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15323 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15324 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15325 | EXPECT_EQ("hello world", response_data); |
| 15326 | |
| 15327 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15328 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15329 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15330 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15331 | |
| 15332 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15333 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15334 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15335 | EXPECT_EQ("falafel", response_data); |
| 15336 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15337 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15338 | } |
| 15339 | |
| 15340 | // Tests that when a SSL connection is established but there's no corresponding |
| 15341 | // request that needs it, the new socket is closed if the transport socket pool |
| 15342 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15343 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15344 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15345 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15346 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15347 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15348 | |
| 15349 | // Set up an ssl request. |
| 15350 | |
| 15351 | HttpRequestInfo ssl_request; |
| 15352 | ssl_request.method = "GET"; |
| 15353 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15354 | |
| 15355 | // No data will be sent on the SSL socket. |
| 15356 | StaticSocketDataProvider ssl_data; |
| 15357 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15358 | |
| 15359 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15361 | |
| 15362 | // Set up HTTP request. |
| 15363 | |
| 15364 | HttpRequestInfo http_request; |
| 15365 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15366 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15367 | |
| 15368 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15369 | MockWrite( |
| 15370 | "GET / HTTP/1.1\r\n" |
| 15371 | "Host: www.example.org\r\n" |
| 15372 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15373 | }; |
| 15374 | MockRead http_reads[] = { |
| 15375 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15376 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15377 | MockRead("falafel"), |
| 15378 | MockRead(SYNCHRONOUS, OK), |
| 15379 | }; |
| 15380 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15381 | http_writes, arraysize(http_writes)); |
| 15382 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15383 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15385 | |
| 15386 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15387 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15388 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15389 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15390 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15391 | |
| 15392 | // Start the HTTP request. Pool should stall. |
| 15393 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15394 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15395 | ASSERT_EQ(ERR_IO_PENDING, |
| 15396 | http_trans.Start(&http_request, http_callback.callback(), |
| 15397 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15398 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15399 | |
| 15400 | // The SSL connection will automatically be closed once the connection is |
| 15401 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15402 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15403 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15404 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15405 | EXPECT_EQ("falafel", response_data); |
| 15406 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15407 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15408 | } |
| 15409 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15410 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15411 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15412 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15413 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15414 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15415 | |
| 15416 | HttpRequestInfo request; |
| 15417 | request.method = "POST"; |
| 15418 | request.url = GURL("http://www.foo.com/"); |
| 15419 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15422 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15423 | // Send headers successfully, but get an error while sending the body. |
| 15424 | MockWrite data_writes[] = { |
| 15425 | MockWrite("POST / HTTP/1.1\r\n" |
| 15426 | "Host: www.foo.com\r\n" |
| 15427 | "Connection: keep-alive\r\n" |
| 15428 | "Content-Length: 3\r\n\r\n"), |
| 15429 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15430 | }; |
| 15431 | |
| 15432 | MockRead data_reads[] = { |
| 15433 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15434 | MockRead("hello world"), |
| 15435 | MockRead(SYNCHRONOUS, OK), |
| 15436 | }; |
| 15437 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15438 | arraysize(data_writes)); |
| 15439 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15440 | |
| 15441 | TestCompletionCallback callback; |
| 15442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15443 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15444 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15445 | |
| 15446 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15447 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15449 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15450 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15451 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15452 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15453 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15454 | |
| 15455 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15456 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15457 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15458 | EXPECT_EQ("hello world", response_data); |
| 15459 | } |
| 15460 | |
| 15461 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15462 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15463 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15464 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15466 | MockWrite data_writes[] = { |
| 15467 | MockWrite("GET / HTTP/1.1\r\n" |
| 15468 | "Host: www.foo.com\r\n" |
| 15469 | "Connection: keep-alive\r\n\r\n"), |
| 15470 | MockWrite("POST / HTTP/1.1\r\n" |
| 15471 | "Host: www.foo.com\r\n" |
| 15472 | "Connection: keep-alive\r\n" |
| 15473 | "Content-Length: 3\r\n\r\n"), |
| 15474 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15475 | }; |
| 15476 | |
| 15477 | MockRead data_reads[] = { |
| 15478 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15479 | "Content-Length: 14\r\n\r\n"), |
| 15480 | MockRead("first response"), |
| 15481 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15482 | "Content-Length: 15\r\n\r\n"), |
| 15483 | MockRead("second response"), |
| 15484 | MockRead(SYNCHRONOUS, OK), |
| 15485 | }; |
| 15486 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15487 | arraysize(data_writes)); |
| 15488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15489 | |
| 15490 | TestCompletionCallback callback; |
| 15491 | HttpRequestInfo request1; |
| 15492 | request1.method = "GET"; |
| 15493 | request1.url = GURL("http://www.foo.com/"); |
| 15494 | request1.load_flags = 0; |
| 15495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15496 | std::unique_ptr<HttpNetworkTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15497 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15498 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15499 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15500 | |
| 15501 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15502 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15503 | |
| 15504 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15505 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15506 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15507 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15508 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15509 | |
| 15510 | std::string response_data1; |
| 15511 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15512 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15513 | EXPECT_EQ("first response", response_data1); |
| 15514 | // Delete the transaction to release the socket back into the socket pool. |
| 15515 | trans1.reset(); |
| 15516 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15517 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15518 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15519 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15520 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15521 | |
| 15522 | HttpRequestInfo request2; |
| 15523 | request2.method = "POST"; |
| 15524 | request2.url = GURL("http://www.foo.com/"); |
| 15525 | request2.upload_data_stream = &upload_data_stream; |
| 15526 | request2.load_flags = 0; |
| 15527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15528 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15529 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15531 | |
| 15532 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15533 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15535 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15536 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15537 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15538 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15539 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15540 | |
| 15541 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15542 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15544 | EXPECT_EQ("second response", response_data2); |
| 15545 | } |
| 15546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15547 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15548 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15549 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15550 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15551 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15552 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15553 | |
| 15554 | HttpRequestInfo request; |
| 15555 | request.method = "POST"; |
| 15556 | request.url = GURL("http://www.foo.com/"); |
| 15557 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15558 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15560 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15561 | // Send headers successfully, but get an error while sending the body. |
| 15562 | MockWrite data_writes[] = { |
| 15563 | MockWrite("POST / HTTP/1.1\r\n" |
| 15564 | "Host: www.foo.com\r\n" |
| 15565 | "Connection: keep-alive\r\n" |
| 15566 | "Content-Length: 3\r\n\r\n" |
| 15567 | "fo"), |
| 15568 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15569 | }; |
| 15570 | |
| 15571 | MockRead data_reads[] = { |
| 15572 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15573 | MockRead("hello world"), |
| 15574 | MockRead(SYNCHRONOUS, OK), |
| 15575 | }; |
| 15576 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15577 | arraysize(data_writes)); |
| 15578 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15579 | |
| 15580 | TestCompletionCallback callback; |
| 15581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15582 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15584 | |
| 15585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15586 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15589 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15590 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15591 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15592 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15593 | |
| 15594 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15595 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15596 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15597 | EXPECT_EQ("hello world", response_data); |
| 15598 | } |
| 15599 | |
| 15600 | // This tests the more common case than the previous test, where headers and |
| 15601 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15602 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15603 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15604 | |
| 15605 | HttpRequestInfo request; |
| 15606 | request.method = "POST"; |
| 15607 | request.url = GURL("http://www.foo.com/"); |
| 15608 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15612 | // Send headers successfully, but get an error while sending the body. |
| 15613 | MockWrite data_writes[] = { |
| 15614 | MockWrite("POST / HTTP/1.1\r\n" |
| 15615 | "Host: www.foo.com\r\n" |
| 15616 | "Connection: keep-alive\r\n" |
| 15617 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15618 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15619 | }; |
| 15620 | |
| 15621 | MockRead data_reads[] = { |
| 15622 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15623 | MockRead("hello world"), |
| 15624 | MockRead(SYNCHRONOUS, OK), |
| 15625 | }; |
| 15626 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15627 | arraysize(data_writes)); |
| 15628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15629 | |
| 15630 | TestCompletionCallback callback; |
| 15631 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15632 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15634 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15635 | // they can't be merged with the body in a single send. Not currently |
| 15636 | // necessary since a chunked body is never merged with headers, but this makes |
| 15637 | // the test more future proof. |
| 15638 | base::RunLoop().RunUntilIdle(); |
| 15639 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15640 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15641 | |
| 15642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15645 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15646 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15647 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15648 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15649 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15650 | |
| 15651 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15652 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15654 | EXPECT_EQ("hello world", response_data); |
| 15655 | } |
| 15656 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15657 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15658 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15659 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15660 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15661 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15662 | |
| 15663 | HttpRequestInfo request; |
| 15664 | request.method = "POST"; |
| 15665 | request.url = GURL("http://www.foo.com/"); |
| 15666 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15667 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15670 | |
| 15671 | MockWrite data_writes[] = { |
| 15672 | MockWrite("POST / HTTP/1.1\r\n" |
| 15673 | "Host: www.foo.com\r\n" |
| 15674 | "Connection: keep-alive\r\n" |
| 15675 | "Content-Length: 3\r\n\r\n"), |
| 15676 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15677 | }; |
| 15678 | |
| 15679 | MockRead data_reads[] = { |
| 15680 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15681 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15682 | MockRead("hello world"), |
| 15683 | MockRead(SYNCHRONOUS, OK), |
| 15684 | }; |
| 15685 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15686 | arraysize(data_writes)); |
| 15687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15688 | |
| 15689 | TestCompletionCallback callback; |
| 15690 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15691 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15693 | |
| 15694 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15695 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15697 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15698 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15699 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15700 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15701 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15702 | |
| 15703 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15704 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15705 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15706 | EXPECT_EQ("hello world", response_data); |
| 15707 | } |
| 15708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15709 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15710 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15711 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15712 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15713 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15714 | |
| 15715 | HttpRequestInfo request; |
| 15716 | request.method = "POST"; |
| 15717 | request.url = GURL("http://www.foo.com/"); |
| 15718 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15722 | // Send headers successfully, but get an error while sending the body. |
| 15723 | MockWrite data_writes[] = { |
| 15724 | MockWrite("POST / HTTP/1.1\r\n" |
| 15725 | "Host: www.foo.com\r\n" |
| 15726 | "Connection: keep-alive\r\n" |
| 15727 | "Content-Length: 3\r\n\r\n"), |
| 15728 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15729 | }; |
| 15730 | |
| 15731 | MockRead data_reads[] = { |
| 15732 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15733 | MockRead("hello world"), |
| 15734 | MockRead(SYNCHRONOUS, OK), |
| 15735 | }; |
| 15736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15737 | arraysize(data_writes)); |
| 15738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15739 | |
| 15740 | TestCompletionCallback callback; |
| 15741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15742 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15744 | |
| 15745 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15746 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15747 | } |
| 15748 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15749 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15750 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15751 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15752 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15753 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15754 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15755 | |
| 15756 | HttpRequestInfo request; |
| 15757 | request.method = "POST"; |
| 15758 | request.url = GURL("http://www.foo.com/"); |
| 15759 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15763 | // Send headers successfully, but get an error while sending the body. |
| 15764 | MockWrite data_writes[] = { |
| 15765 | MockWrite("POST / HTTP/1.1\r\n" |
| 15766 | "Host: www.foo.com\r\n" |
| 15767 | "Connection: keep-alive\r\n" |
| 15768 | "Content-Length: 3\r\n\r\n"), |
| 15769 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15770 | }; |
| 15771 | |
| 15772 | MockRead data_reads[] = { |
| 15773 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15774 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15775 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15776 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15777 | MockRead(SYNCHRONOUS, OK), |
| 15778 | }; |
| 15779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15780 | arraysize(data_writes)); |
| 15781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15782 | |
| 15783 | TestCompletionCallback callback; |
| 15784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15787 | |
| 15788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15789 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15790 | } |
| 15791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15792 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15793 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15794 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15795 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15796 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15797 | |
| 15798 | HttpRequestInfo request; |
| 15799 | request.method = "POST"; |
| 15800 | request.url = GURL("http://www.foo.com/"); |
| 15801 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15805 | // Send headers successfully, but get an error while sending the body. |
| 15806 | MockWrite data_writes[] = { |
| 15807 | MockWrite("POST / HTTP/1.1\r\n" |
| 15808 | "Host: www.foo.com\r\n" |
| 15809 | "Connection: keep-alive\r\n" |
| 15810 | "Content-Length: 3\r\n\r\n"), |
| 15811 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15812 | }; |
| 15813 | |
| 15814 | MockRead data_reads[] = { |
| 15815 | MockRead("HTTP 0.9 rocks!"), |
| 15816 | MockRead(SYNCHRONOUS, OK), |
| 15817 | }; |
| 15818 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15819 | arraysize(data_writes)); |
| 15820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15821 | |
| 15822 | TestCompletionCallback callback; |
| 15823 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15824 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15826 | |
| 15827 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15828 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15829 | } |
| 15830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15831 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15832 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15833 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15834 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15835 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15836 | |
| 15837 | HttpRequestInfo request; |
| 15838 | request.method = "POST"; |
| 15839 | request.url = GURL("http://www.foo.com/"); |
| 15840 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15841 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15844 | // Send headers successfully, but get an error while sending the body. |
| 15845 | MockWrite data_writes[] = { |
| 15846 | MockWrite("POST / HTTP/1.1\r\n" |
| 15847 | "Host: www.foo.com\r\n" |
| 15848 | "Connection: keep-alive\r\n" |
| 15849 | "Content-Length: 3\r\n\r\n"), |
| 15850 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15851 | }; |
| 15852 | |
| 15853 | MockRead data_reads[] = { |
| 15854 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15855 | MockRead(SYNCHRONOUS, OK), |
| 15856 | }; |
| 15857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15858 | arraysize(data_writes)); |
| 15859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15860 | |
| 15861 | TestCompletionCallback callback; |
| 15862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15863 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15865 | |
| 15866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15867 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15868 | } |
| 15869 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15870 | // Verify that proxy headers are not sent to the destination server when |
| 15871 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15872 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15873 | HttpRequestInfo request; |
| 15874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15875 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15876 | AddWebSocketHeaders(&request.extra_headers); |
| 15877 | |
| 15878 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15879 | session_deps_.proxy_service = |
| 15880 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15881 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15883 | |
| 15884 | // Since a proxy is configured, try to establish a tunnel. |
| 15885 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15886 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15887 | "Host: www.example.org:443\r\n" |
| 15888 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15889 | |
| 15890 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15891 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15892 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15893 | "Host: www.example.org:443\r\n" |
| 15894 | "Proxy-Connection: keep-alive\r\n" |
| 15895 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15896 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15897 | MockWrite("GET / HTTP/1.1\r\n" |
| 15898 | "Host: www.example.org\r\n" |
| 15899 | "Connection: Upgrade\r\n" |
| 15900 | "Upgrade: websocket\r\n" |
| 15901 | "Origin: http://www.example.org\r\n" |
| 15902 | "Sec-WebSocket-Version: 13\r\n" |
| 15903 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15904 | }; |
| 15905 | |
| 15906 | // The proxy responds to the connect with a 407, using a persistent |
| 15907 | // connection. |
| 15908 | MockRead data_reads[] = { |
| 15909 | // No credentials. |
| 15910 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15911 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15912 | MockRead("Content-Length: 0\r\n"), |
| 15913 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15914 | |
| 15915 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15916 | |
| 15917 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15918 | MockRead("Upgrade: websocket\r\n"), |
| 15919 | MockRead("Connection: Upgrade\r\n"), |
| 15920 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15921 | }; |
| 15922 | |
| 15923 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15924 | arraysize(data_writes)); |
| 15925 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15926 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15927 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15929 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15930 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15931 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15932 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15933 | &websocket_stream_create_helper); |
| 15934 | |
| 15935 | { |
| 15936 | TestCompletionCallback callback; |
| 15937 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15938 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15940 | |
| 15941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15942 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15943 | } |
| 15944 | |
| 15945 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15946 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15947 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15948 | EXPECT_EQ(407, response->headers->response_code()); |
| 15949 | |
| 15950 | { |
| 15951 | TestCompletionCallback callback; |
| 15952 | |
| 15953 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15954 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15956 | |
| 15957 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15958 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15959 | } |
| 15960 | |
| 15961 | response = trans->GetResponseInfo(); |
| 15962 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15963 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15964 | |
| 15965 | EXPECT_EQ(101, response->headers->response_code()); |
| 15966 | |
| 15967 | trans.reset(); |
| 15968 | session->CloseAllConnections(); |
| 15969 | } |
| 15970 | |
| 15971 | // Verify that proxy headers are not sent to the destination server when |
| 15972 | // establishing a tunnel for an insecure WebSocket connection. |
| 15973 | // This requires the authentication info to be injected into the auth cache |
| 15974 | // due to crbug.com/395064 |
| 15975 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15976 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15977 | HttpRequestInfo request; |
| 15978 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15979 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15980 | AddWebSocketHeaders(&request.extra_headers); |
| 15981 | |
| 15982 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15983 | session_deps_.proxy_service = |
| 15984 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15985 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15987 | |
| 15988 | MockWrite data_writes[] = { |
| 15989 | // Try to establish a tunnel for the WebSocket connection, with |
| 15990 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15991 | // they cannot and will not use the same TCP/IP connection as the |
| 15992 | // preflight HTTP request. |
| 15993 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15994 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15995 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15996 | "Proxy-Connection: keep-alive\r\n" |
| 15997 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15998 | |
| 15999 | MockWrite( |
| 16000 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16001 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16002 | "Connection: Upgrade\r\n" |
| 16003 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16004 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16005 | "Sec-WebSocket-Version: 13\r\n" |
| 16006 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16007 | }; |
| 16008 | |
| 16009 | MockRead data_reads[] = { |
| 16010 | // HTTP CONNECT with credentials. |
| 16011 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16012 | |
| 16013 | // WebSocket connection established inside tunnel. |
| 16014 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16015 | MockRead("Upgrade: websocket\r\n"), |
| 16016 | MockRead("Connection: Upgrade\r\n"), |
| 16017 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16018 | }; |
| 16019 | |
| 16020 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16021 | arraysize(data_writes)); |
| 16022 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16023 | |
| 16024 | session->http_auth_cache()->Add( |
| 16025 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16026 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16028 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16030 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16031 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16032 | &websocket_stream_create_helper); |
| 16033 | |
| 16034 | TestCompletionCallback callback; |
| 16035 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16036 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16038 | |
| 16039 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16040 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16041 | |
| 16042 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16043 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16044 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16045 | |
| 16046 | EXPECT_EQ(101, response->headers->response_code()); |
| 16047 | |
| 16048 | trans.reset(); |
| 16049 | session->CloseAllConnections(); |
| 16050 | } |
| 16051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16052 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16053 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16054 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16055 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16056 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16057 | |
| 16058 | HttpRequestInfo request; |
| 16059 | request.method = "POST"; |
| 16060 | request.url = GURL("http://www.foo.com/"); |
| 16061 | request.upload_data_stream = &upload_data_stream; |
| 16062 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16064 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16065 | MockWrite data_writes[] = { |
| 16066 | MockWrite("POST / HTTP/1.1\r\n" |
| 16067 | "Host: www.foo.com\r\n" |
| 16068 | "Connection: keep-alive\r\n" |
| 16069 | "Content-Length: 3\r\n\r\n"), |
| 16070 | MockWrite("foo"), |
| 16071 | }; |
| 16072 | |
| 16073 | MockRead data_reads[] = { |
| 16074 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16075 | MockRead(SYNCHRONOUS, OK), |
| 16076 | }; |
| 16077 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16078 | arraysize(data_writes)); |
| 16079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16080 | |
| 16081 | TestCompletionCallback callback; |
| 16082 | |
| 16083 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16084 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16085 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16086 | |
| 16087 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16089 | |
| 16090 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16091 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16092 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16093 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16094 | } |
| 16095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16096 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16097 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16098 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16099 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16100 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16101 | |
| 16102 | HttpRequestInfo request; |
| 16103 | request.method = "POST"; |
| 16104 | request.url = GURL("http://www.foo.com/"); |
| 16105 | request.upload_data_stream = &upload_data_stream; |
| 16106 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16107 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16108 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16109 | MockWrite data_writes[] = { |
| 16110 | MockWrite("POST / HTTP/1.1\r\n" |
| 16111 | "Host: www.foo.com\r\n" |
| 16112 | "Connection: keep-alive\r\n" |
| 16113 | "Content-Length: 3\r\n\r\n"), |
| 16114 | MockWrite("foo"), |
| 16115 | }; |
| 16116 | |
| 16117 | MockRead data_reads[] = { |
| 16118 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16119 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16120 | MockRead(SYNCHRONOUS, OK), |
| 16121 | }; |
| 16122 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16123 | arraysize(data_writes)); |
| 16124 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16125 | |
| 16126 | TestCompletionCallback callback; |
| 16127 | |
| 16128 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16129 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16130 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16131 | |
| 16132 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16133 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16134 | |
| 16135 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16136 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16137 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16138 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16139 | } |
| 16140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16141 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16142 | ChunkedUploadDataStream upload_data_stream(0); |
| 16143 | |
| 16144 | HttpRequestInfo request; |
| 16145 | request.method = "POST"; |
| 16146 | request.url = GURL("http://www.foo.com/"); |
| 16147 | request.upload_data_stream = &upload_data_stream; |
| 16148 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16150 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16151 | // Send headers successfully, but get an error while sending the body. |
| 16152 | MockWrite data_writes[] = { |
| 16153 | MockWrite("POST / HTTP/1.1\r\n" |
| 16154 | "Host: www.foo.com\r\n" |
| 16155 | "Connection: keep-alive\r\n" |
| 16156 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16157 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16158 | }; |
| 16159 | |
| 16160 | MockRead data_reads[] = { |
| 16161 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16162 | MockRead(SYNCHRONOUS, OK), |
| 16163 | }; |
| 16164 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16165 | arraysize(data_writes)); |
| 16166 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16167 | |
| 16168 | TestCompletionCallback callback; |
| 16169 | |
| 16170 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16171 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16172 | |
| 16173 | base::RunLoop().RunUntilIdle(); |
| 16174 | upload_data_stream.AppendData("f", 1, false); |
| 16175 | |
| 16176 | base::RunLoop().RunUntilIdle(); |
| 16177 | upload_data_stream.AppendData("oo", 2, true); |
| 16178 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16179 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16180 | |
| 16181 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16182 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16183 | |
| 16184 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16185 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16186 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16187 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16188 | } |
| 16189 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16190 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16191 | // the unthrottled state are not blocked. |
| 16192 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16193 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16194 | std::unique_ptr<HttpNetworkSession> session( |
| 16195 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16196 | |
| 16197 | // Send a simple request and make sure it goes through. |
| 16198 | HttpRequestInfo request; |
| 16199 | request.method = "GET"; |
| 16200 | request.url = GURL("http://www.example.org/"); |
| 16201 | |
| 16202 | std::unique_ptr<HttpTransaction> trans( |
| 16203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16204 | |
| 16205 | MockWrite data_writes[] = { |
| 16206 | MockWrite("GET / HTTP/1.1\r\n" |
| 16207 | "Host: www.example.org\r\n" |
| 16208 | "Connection: keep-alive\r\n\r\n"), |
| 16209 | }; |
| 16210 | MockRead data_reads[] = { |
| 16211 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16212 | MockRead(SYNCHRONOUS, OK), |
| 16213 | }; |
| 16214 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16215 | arraysize(data_writes)); |
| 16216 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16217 | |
| 16218 | TestCompletionCallback callback; |
| 16219 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16220 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16221 | } |
| 16222 | |
| 16223 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16224 | // when the throttle is unblocked. |
| 16225 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16226 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16227 | std::unique_ptr<HttpNetworkSession> session( |
| 16228 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16229 | |
| 16230 | // Send a simple request and make sure it goes through. |
| 16231 | HttpRequestInfo request; |
| 16232 | request.method = "GET"; |
| 16233 | request.url = GURL("http://www.example.org/"); |
| 16234 | |
| 16235 | MockWrite data_writes[] = { |
| 16236 | MockWrite("GET / HTTP/1.1\r\n" |
| 16237 | "Host: www.example.org\r\n" |
| 16238 | "Connection: keep-alive\r\n\r\n"), |
| 16239 | }; |
| 16240 | MockRead data_reads[] = { |
| 16241 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16242 | MockRead(SYNCHRONOUS, OK), |
| 16243 | }; |
| 16244 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16245 | arraysize(data_writes)); |
| 16246 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16247 | |
| 16248 | // Start a request that will be throttled at start; confirm it |
| 16249 | // doesn't complete. |
| 16250 | throttler->set_throttle_new_requests(true); |
| 16251 | std::unique_ptr<HttpTransaction> trans( |
| 16252 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16253 | |
| 16254 | TestCompletionCallback callback; |
| 16255 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16257 | |
| 16258 | base::RunLoop().RunUntilIdle(); |
| 16259 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16260 | EXPECT_FALSE(callback.have_result()); |
| 16261 | |
| 16262 | // Confirm the request goes on to complete when unthrottled. |
| 16263 | throttler->UnthrottleAllRequests(); |
| 16264 | base::RunLoop().RunUntilIdle(); |
| 16265 | ASSERT_TRUE(callback.have_result()); |
| 16266 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16267 | } |
| 16268 | |
| 16269 | // Destroy a request while it's throttled. |
| 16270 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16271 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16272 | std::unique_ptr<HttpNetworkSession> session( |
| 16273 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16274 | |
| 16275 | // Send a simple request and make sure it goes through. |
| 16276 | HttpRequestInfo request; |
| 16277 | request.method = "GET"; |
| 16278 | request.url = GURL("http://www.example.org/"); |
| 16279 | |
| 16280 | MockWrite data_writes[] = { |
| 16281 | MockWrite("GET / HTTP/1.1\r\n" |
| 16282 | "Host: www.example.org\r\n" |
| 16283 | "Connection: keep-alive\r\n\r\n"), |
| 16284 | }; |
| 16285 | MockRead data_reads[] = { |
| 16286 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16287 | MockRead(SYNCHRONOUS, OK), |
| 16288 | }; |
| 16289 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16290 | arraysize(data_writes)); |
| 16291 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16292 | |
| 16293 | // Start a request that will be throttled at start; confirm it |
| 16294 | // doesn't complete. |
| 16295 | throttler->set_throttle_new_requests(true); |
| 16296 | std::unique_ptr<HttpTransaction> trans( |
| 16297 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16298 | |
| 16299 | TestCompletionCallback callback; |
| 16300 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16301 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16302 | |
| 16303 | base::RunLoop().RunUntilIdle(); |
| 16304 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16305 | EXPECT_FALSE(callback.have_result()); |
| 16306 | |
| 16307 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16308 | trans.reset(); |
| 16309 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16310 | } |
| 16311 | |
| 16312 | // Confirm the throttler receives SetPriority calls. |
| 16313 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16314 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16315 | std::unique_ptr<HttpNetworkSession> session( |
| 16316 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16317 | |
| 16318 | // Send a simple request and make sure it goes through. |
| 16319 | HttpRequestInfo request; |
| 16320 | request.method = "GET"; |
| 16321 | request.url = GURL("http://www.example.org/"); |
| 16322 | |
| 16323 | MockWrite data_writes[] = { |
| 16324 | MockWrite("GET / HTTP/1.1\r\n" |
| 16325 | "Host: www.example.org\r\n" |
| 16326 | "Connection: keep-alive\r\n\r\n"), |
| 16327 | }; |
| 16328 | MockRead data_reads[] = { |
| 16329 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16330 | MockRead(SYNCHRONOUS, OK), |
| 16331 | }; |
| 16332 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16333 | arraysize(data_writes)); |
| 16334 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16335 | |
| 16336 | throttler->set_throttle_new_requests(true); |
| 16337 | std::unique_ptr<HttpTransaction> trans( |
| 16338 | new HttpNetworkTransaction(IDLE, session.get())); |
| 16339 | // Start the transaction to associate a throttle with it. |
| 16340 | TestCompletionCallback callback; |
| 16341 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16342 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16343 | |
| 16344 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16345 | trans->SetPriority(LOW); |
| 16346 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16347 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16348 | |
| 16349 | throttler->UnthrottleAllRequests(); |
| 16350 | base::RunLoop().RunUntilIdle(); |
| 16351 | ASSERT_TRUE(callback.have_result()); |
| 16352 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16353 | } |
| 16354 | |
| 16355 | // Confirm that unthrottling from a SetPriority call by the |
| 16356 | // throttler works properly. |
| 16357 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16358 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16359 | std::unique_ptr<HttpNetworkSession> session( |
| 16360 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16361 | |
| 16362 | // Send a simple request and make sure it goes through. |
| 16363 | HttpRequestInfo request; |
| 16364 | request.method = "GET"; |
| 16365 | request.url = GURL("http://www.example.org/"); |
| 16366 | |
| 16367 | MockWrite data_writes[] = { |
| 16368 | MockWrite("GET / HTTP/1.1\r\n" |
| 16369 | "Host: www.example.org\r\n" |
| 16370 | "Connection: keep-alive\r\n\r\n"), |
| 16371 | }; |
| 16372 | MockRead data_reads[] = { |
| 16373 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16374 | MockRead(SYNCHRONOUS, OK), |
| 16375 | }; |
| 16376 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16377 | arraysize(data_writes)); |
| 16378 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16379 | |
| 16380 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16381 | data_writes, arraysize(data_writes)); |
| 16382 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16383 | |
| 16384 | // Start a request that will be throttled at start; confirm it |
| 16385 | // doesn't complete. |
| 16386 | throttler->set_throttle_new_requests(true); |
| 16387 | std::unique_ptr<HttpTransaction> trans( |
| 16388 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16389 | |
| 16390 | TestCompletionCallback callback; |
| 16391 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16392 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16393 | |
| 16394 | base::RunLoop().RunUntilIdle(); |
| 16395 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16396 | EXPECT_FALSE(callback.have_result()); |
| 16397 | |
| 16398 | // Create a new request, call SetPriority on it to unthrottle, |
| 16399 | // and make sure that allows the original request to complete. |
| 16400 | std::unique_ptr<HttpTransaction> trans1( |
| 16401 | new HttpNetworkTransaction(LOW, session.get())); |
| 16402 | throttler->set_priority_change_closure( |
| 16403 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16404 | base::Unretained(throttler))); |
| 16405 | |
| 16406 | // Start the transaction to associate a throttle with it. |
| 16407 | TestCompletionCallback callback1; |
| 16408 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16410 | |
| 16411 | trans1->SetPriority(IDLE); |
| 16412 | |
| 16413 | base::RunLoop().RunUntilIdle(); |
| 16414 | ASSERT_TRUE(callback.have_result()); |
| 16415 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16416 | ASSERT_TRUE(callback1.have_result()); |
| 16417 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16418 | } |
| 16419 | |
| 16420 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
| 16421 | void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {} |
| 16422 | |
| 16423 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16424 | // throttler works properly. |
| 16425 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16426 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16427 | std::unique_ptr<HttpNetworkSession> session( |
| 16428 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16429 | |
| 16430 | // Send a simple request and make sure it goes through. |
| 16431 | HttpRequestInfo request; |
| 16432 | request.method = "GET"; |
| 16433 | request.url = GURL("http://www.example.org/"); |
| 16434 | |
| 16435 | MockWrite data_writes[] = { |
| 16436 | MockWrite("GET / HTTP/1.1\r\n" |
| 16437 | "Host: www.example.org\r\n" |
| 16438 | "Connection: keep-alive\r\n\r\n"), |
| 16439 | }; |
| 16440 | MockRead data_reads[] = { |
| 16441 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16442 | MockRead(SYNCHRONOUS, OK), |
| 16443 | }; |
| 16444 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16445 | arraysize(data_writes)); |
| 16446 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16447 | |
| 16448 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16449 | data_writes, arraysize(data_writes)); |
| 16450 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16451 | |
| 16452 | // Start a request that will be throttled at start; confirm it |
| 16453 | // doesn't complete. |
| 16454 | throttler->set_throttle_new_requests(true); |
| 16455 | std::unique_ptr<HttpTransaction> trans( |
| 16456 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16457 | |
| 16458 | TestCompletionCallback callback; |
| 16459 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16460 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16461 | |
| 16462 | base::RunLoop().RunUntilIdle(); |
| 16463 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16464 | EXPECT_FALSE(callback.have_result()); |
| 16465 | |
| 16466 | // Arrange for the set priority call on the above transaction to delete |
| 16467 | // the transaction. |
| 16468 | HttpTransaction* trans_ptr(trans.get()); |
| 16469 | throttler->set_priority_change_closure( |
| 16470 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16471 | |
| 16472 | // Call it and check results (partially a "doesn't crash" test). |
| 16473 | trans_ptr->SetPriority(IDLE); |
| 16474 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16475 | |
| 16476 | base::RunLoop().RunUntilIdle(); |
| 16477 | ASSERT_FALSE(callback.have_result()); |
| 16478 | } |
| 16479 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16480 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16481 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16482 | const std::string https_url = "https://www.example.com"; |
| 16483 | HttpRequestInfo request; |
| 16484 | request.url = GURL(https_url); |
| 16485 | request.method = "GET"; |
| 16486 | |
| 16487 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16488 | ssl.token_binding_negotiated = true; |
| 16489 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16490 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16492 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16493 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16494 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16495 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16496 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16497 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16499 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 16500 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16502 | |
| 16503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16504 | TestCompletionCallback callback; |
| 16505 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16506 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16507 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16508 | |
| 16509 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16510 | HttpRequestHeaders headers; |
| 16511 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16512 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16513 | } |
| 16514 | #endif // !defined(OS_IOS) |
| 16515 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16516 | } // namespace net |